C++11: C99 long long
sumi_cj 270001SV2S Visits (7619)
Compared with C++98, C++11 supports two integer types long long and unsigned long long, which were introduced in the C99 standard before. The C++11 standard supports these two integer types to be compatible with the C99 standard.
The long long and unsigned long long types can have different lengths on difference platforms, but the C++11 standard requires that their length should be at least 64 bits. When we define an integer literal, we can use suffix LL (ll) to indicate the type of the literal is long long, and use suffix ULL (ull, Ull, uLL) to indicate the type of the literal is unsigned long long. In the following example, variable x is of type long long and its value is -950
long long int x = -950
unsigned long long y = 9500
We call this feature as the C99 long long feature. The following example shows the different behaviors when the C99 long long feature is enabled and disabled:
printf("C99 long long is enabled");
printf("C99 long long is disabled");
In this example, the values 3999999999 and 4000000000 are too large to fit into the 32-bit long int type, but they can fit into either the unsigned long or the long long int type. If the C99 long long feature is enabled, the two values have the long long int type, so the difference of 3999999999 and 4000000000 is negative. Otherwise, if the C99 long long feature is disabled, the two values have the unsigned long type, so the difference is positive.
To strictly conform to the C++11 standard, the IBM XL C/C++ compiler introduces the extended integer safe behavior to ensure that a signed value never becomes an unsigned value after a promotion. After this behavior is enabled, if a decimal integer literal that does not have a suffix containing u or U cannot be represented by the long long int type, the compiler issues an error message to indicate that the value of the literal is out of range.