As I understand it, the C specification says that type int
is supposed to be the most efficient type on target platform that contains at least 16 bits.
Isn't that exactly what the C99 definition of int_fast16_t
is too?
Maybe they put it in there just for consistency, since the other int_fastXX_t
are needed?
Update
To summarize discussion below:
Example: MSVC on x86-64 has a 32-bit int, even on 64-bit systems. MS chose to do this because too many people assumed int would always be exactly 32-bits, and so a lot of ABIs would break. However, it's possible that int_fast32_t would be a 64-bit number if 64-bit values were faster on x86-64. (Which I don't think is actually the case, but it just demonstrates the point)
int
is a "most efficient type" in speed/size - but that is not specified by per the C spec. It must be 16 or more bits.
int_fast16_t
is most efficient type in speed with at least the range of a 16 bit int.
Example: A given platform may have decided that int
should be 32-bit for many reasons, not only speed. The same system may find a different type is fastest for 16-bit integers.
Example: In a 64-bit machine, where one would expect to have int
as 64-bit, a compiler may use a mode with 32-bit int
compilation for compatibility. In this mode, int_fast16_t
could be 64-bit as that is natively the fastest width for it avoids alignment issues, etc.