Does the C99 standard mandate that a conforming compiler have a 64-bit
int64_t defined (and usable)? Or is it optional, and just happens to
be defined by all popular compilers?
The type is optional, in one sense, and conditionally required in a different sense. Specifically, C99 says,
The typedef name intN_t designates a signed integer type with width N
, no padding bits, and a two's complement representation. [...]
These types are optional. However, if an implementation provides
integer types with widths of 8, 16, 32, or 64 bits, no padding bits,
and (for the signed types) that have a two's complement
representation, it shall define the corresponding typedef names.
Thus, int64_t
is optional in the sense that a conforming implementation is not required to provide any type that exactly matches the characteristics of an int64_t
, and if it doesn't, then it needn't (indeed, must not, according to another section) provide type int64_t
.
C99 does specify that there is a type long long int
whose required minimum range necessitates a representation at least 64 bits wide. Now it is possible that in some implementation there is no signed integer type exactly 64 bits wide (for example, maybe int
is 24 bits, long
48, and long long
96), and it is possible that there is a 64-value-bit integer type, but it contains padding bits or is not represented in two's complement. Such implementations could be fully conforming and yet not define an int64_t
. In practice, though, there aren't any such implementations in common use today.