Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

error C2177: constant too big

Posted on 2004-09-23
5
Medium Priority
?
923 Views
Last Modified: 2008-01-09
Hello.
I have this code:
------CODE-----
char buff[ 256 ];
buff=0x53006500630052004500740030003100;
-----\CODE-----
Which gives these errors:
-----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
-----\ERRORS-----

What am I doing wrong?? The text on msdn didn't helped.
0
Comment
Question by:Kappa_Alfa_Kappa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12138383
buff=0x53006500630052004500740030003100;
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:
buff=0x5300650063005200;
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12138392
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.
0
 

Accepted Solution

by:
feldspar2 earned 320 total points
ID: 12138819
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



0
 
LVL 3

Expert Comment

by:teratoma
ID: 12140284
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.
0
 

Author Comment

by:Kappa_Alfa_Kappa
ID: 12140860
Thanks, that's what I wanted to know...
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question