PDA

View Full Version : 64-bit types in C++


sciguy125
1st October 2004, 05:19 AM
I'm using g++ to (obviously) compile a C++ program.

I have a variable of type unsigned long long. I know that it's 64-bits because sizeof says that it's 8 bytes. I also ran a loop with a counter to see how big it is. If I have something during run time store an obsenely large number in it (something within it's limits... <2^64), it works and is able to output it to the screen. If I try to store a large number during compile time, it doesn't like it. I get the following error:

main.cpp:30: error: integer constant is too large for "long" type

here's the relevant code:

typedef unsigned long long int64;
int64 test_time = 62000000000;

It looks like it thinks that test_time is a long.

tashirosgt
1st October 2004, 03:54 PM
Put an "LL" at the end of your constant. I think what is happening is that without the LL, the compiler tries to interpret the constant on the right hand side as a long integer instead of a long long . It thinks you've made an error on the right hand side of the initialization, it never gets to the point of considering whether the right hand side would fit in the left hand side.

Edit: To be specific:

int64 test_time = 62000000000LL;

sciguy125
2nd October 2004, 07:49 AM
That did it.

Thanks

Dindigul Travel Photos on Instagram - Minggang Instagram Photos - Fermo