If I compile a program with -std=c99 and do a sizeof of a constant that is larger then LONG_LONG_MAX but smaller then ULONG_LONG_MAX I get 16 instead of 8. For values larger then ULONG_LONG_MAX I get 8. I can reproduce this on x86 Linux and IA64 HP-UX (and probably other systems). Here is a test case that should show the problem on any systems where LONG LONG is 8 bytes. Compiled without -std=c99 all the prints will print '8', with '-std=c99' the middle two prints will print out 16 instead of 8. Reproducable with ToT and going back to at least 4.1.0. #include <stdio.h> main() { /* LONG_LONG_MAX */ printf("%ld\n", sizeof(9223372036854775807LL)); /* LONG_LONG_MAX + 1 */ printf("%ld\n", sizeof(9223372036854775808LL)); /* ULONG_LONG_MAX as a long long type */ printf("%ld\n", sizeof(18446744073709551615LL)); /* ULONG_LONG_MAX + 1 as a long long type */ printf("%ld\n", sizeof(18446744073709551616LL)); }
t.c:7:32: warning: integer constant is so large that it is unsigned t.c:9:32: warning: integer constant is so large that it is unsigned t.c:11:32: warning: integer constant is too large for its type
§6.4.4.1 Integer constants: If an integer constant cannot be represented by any type in its list, it may have an extended integer type, if the extended integer type can represent its value. If all of the types in the list for the constant are signed, the extended integer type shall be signed. Thus 9223372036854775808LL will be of some signed extended type, since it does not fit in long long.
(In reply to comment #2) > §6.4.4.1 Integer constants: > > If an integer constant cannot be represented by any type in its list, it may > have an extended integer type, if the extended integer type can represent its > value. If all of the types in the list for the constant are signed, the > extended integer type shall be signed. > > Thus 9223372036854775808LL will be of some signed extended type, since it does > not fit in long long. It *may* have an extended integer type. If it doesn't (and it doesn't: gcc doesn't have any of the standard's extended integer types, see http://gcc.gnu.org/onlinedocs/gcc-4.4.3/gcc/Integers-implementation.html), such a constant is simply invalid, and gcc, after reporting that, is free to make the code behave however it likes. At least, as far as the standard is concerned.