[Solved] Using ULL suffix in C++ code compiled on RHEL6.4

Hi,

I am trying to compile a piece of c++ code using the g++ compiler on an RHEL6.4 system. Here is a code snippet:

#define CDMA_TIME_OFFSET     315964800000ULL
unsigned long long int ABC=CDMA_TIME_OFFSET;

For some reason, the value assigned to ABC is only the LSB 32-bit of CDMA_TIME_OFFSET. The MSB 32-bit is being ignored.

Below are the relevant compiler options that I am using:

./x86_64-redhat-linux-gnu-g++ -c -g -pthread -lpthread -m32 -O3 -fno-strict-aliasing -ffast-math -fno-trapping-math -std=c99 

Note that I have already tried including the -std=c99 option but that did not help. Could the -m32 that I have used be the reason for MSB 32-bit being ignored?

Thanks !

Without -m32, 'unsigned long long' may not be valid at all.

How are you checking whether the upper 32 bits have been discarded? Your code works perfectly fine here, I suspect the way you're printing them is truncating it. This is how I print it:

printf("%qd\n", ABC);

I rechecked my code and realized that some place I was typecasting the ULL value with an "unsinged". It seems this was causing the value to be truncated to a 32-bit number:

unsigned long long int ABC=(unsigned)CDMA_TIME_OFFSET;

After removing the "unsigned" typecasting, the values are coming good.

Thanks!

1 Like