Pelles C forum
C language => Expert questions => Topic started by: Logman on March 02, 2019, 09:35:37 pm

I've been using Pelles 64bit C version for over two years now and just ran into the following problem for the first time. I set up a program like this:
unsigned long long int num = 18446744073709551615; // largest unsigned long long int
printf("num = %llu\n", num);
and it always converts this value to: 9223372036854775807, the largest long long int value. I assume that there is an overflow or two's complement occuring, but haven't been able to determine where or how. Ostensibly, 18446744073709551615 is an 8 byte (64bit) value. Am I doing something wrong?
Logman

Hello Logman, welcom on PellesC forum.
It seems a problem with preprocessor that doesn't interpret well the value without explicit unsigned suffix, in this case 'ULL' for unsigned long long.
Adding it to the assignment solve the problem as in the snippet below:
unsigned long long int num = 18446744073709551615ULL; // largest unsigned long long int
printf("num = %llu\n", num);
I can't tell you right now if this is a bug or not. I have to check specs. In any case interpreting the input as signed and truncating it should preferably trigger a warning at least.
Anyway I hope that you can solve your problem for now.

Yes, the 'ULL' suffix seems to work. Thank you for the input. I really needed to be able to process large unsigned long long int values in a weather simulation program I'm working on and this did the trick.
Logman

To save you some typing ;), the 'U' suffix should be enough (without any suffix the constant is interpreted as signed long long).

ISO/IEC 9899:TC2 Committee Draft — May 6, 2005 WG14/N1124
ISO/IEC 9899:TC2 Committee Draft — May 6, 2005 WG14/N1124
Suffix Decimal Constant Octal or Hexadecimal Constant
none int int
long int unsigned int
long long int long int
unsigned long int
long long int
unsigned long long int
u or U unsigned int unsigned int
unsigned long int unsigned long int
unsigned long long int unsigned long long int
l or L long int long int
long long int unsigned long int
long long int
unsigned long long int