• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 997
  • Last Modified:

error C2177: constant too big

I have this code:
char buff[ 256 ];
Which gives these errors:
error C2177: constant too big
error C2440: '=' : cannot convert from 'const int' to 'char [256]'
        There are no conversions to array types, although there are conversions to references or pointers to arrays

What am I doing wrong?? The text on msdn didn't helped.
1 Solution
Jaime OlivaresSoftware ArchitectCommented:
Definitively it won't work in every compiler I know.

Largest value you can have (as far as I know) is 64 bits, that is 16 hex digits. Something like:
Jaime OlivaresSoftware ArchitectCommented:
What is exactly what you want to do? You are declaring a char array, but you are trying to asign it an big number, that doesn't seems reasonably. Maybe you can post more code.
To populate your buffer you will need to use syntax that specifies it as an array:

char buff[256] = {0x53, 0x00, 0x65, ...};  //  a list of 256 one-bye chars

The "constant too big" error is because any manifest constant must be able to fit into one of the built-in types.  0x53006500630052004500740030003100 is a 16-byte value that won't fit into any int or long or long long, because these types are at max 64 bits or 8 bytes.

The "cannot convert from 'const int' to 'char [256]" error is because buff is an array, and an array is not something that can be assigned to (an lvalue).  feldspar2 gives the correct syntax for initializing an array, which is not the same thing as assignment.  If you need to declare your array first and later fill it with values, use strcpy, memcpy, or something similar.

What you probably want to do is to declare your constant as a string like this:

const char buf[] = "53006500630052004500740030003100";

Then you can tear it apart piece by piece using various library functions for converting strings to integers.  Check out stringstream in your favorite C++ book.
Kappa_Alfa_KappaAuthor Commented:
Thanks, that's what I wanted to know...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now