Reputation: 81
I was looking at limits.h on windows and found this:
#define LLONG_MAX 9223372036854775807i64 // maximum signed long long int value
#define LLONG_MIN (-9223372036854775807i64 - 1) // minimum signed long long int value
#define ULLONG_MAX 0xffffffffffffffffui64 // maximum unsigned long long int value
What does the i64
at the end of the value mean?
Upvotes: 7
Views: 4633
Reputation: 144951
The i64
suffix is a Microsoft extension to specify 64-bit integer constants.
A portable alternative is (int64_t)9223372036854775807
, but older versions of Microsoft C did not support C99 <stdint.h>
types.
You can also use the standard suffix LL
to specify a constant of of type long long
, which has at least 63 value bits, but may have more on some platforms. The case of L
is not significant, so 1ll
is equivalent to 1LL
, but significantly more confusing because l
looks a lot like 1
, especially with some fixed type fonts.
Note that 9223372036854775807
as an integer constant has the smallest type with enough range to express it in the list int
, long int
, long long int
. Given the common sizes for these types on Microsoft platforms, the type long long int
is probably the only one with 64-bits.
The suffix is more useful for smaller constants such as 1
as show below:
uint64_t x = 1 << 32; // undefined behavior
uint64_t x = 1ULL << 32; // fully defined, x is 0x800000000
uint64_t x = 1ui64 << 32; // Microsoft specific, non portable
Upvotes: 8