cstdintcstdint

Why is int_fast16_t 64 bits on a 64-bit system?


I looked inside the header file <stdint.h> on my implementation. I see the following:

typedef long int int_fast16_t;
typedef long int int_fast32_t;
typedef long int int_fast64_t;

I have a 64-bit system, so a long int occupies 64 bits. Why are all three data types typedefed as being long ints? I understand the case of the int_fast64_t, which is 64 bits. But why are the 16 and 32-bit data types having 64 bits? Is this some kind of error? I created a small program to check if this is the case:

sizeof(int_fast8_t) : 1
sizeof(int_fast16_t) : 8
sizeof(int_fast32_t) : 8
sizeof(int_fast64_t) : 8

Are the sizes of these data types implementation defined? What features or characteristics defines a data type as being "fast"? Is it the speed that chunks of data get loaded from the RAM to the CPU? If int_fast16_t and int_fast32_t are 8 bytes wide, what are the benefits in performance? Is it really faster to access a 64-bit data type on a 64-bit system?


Solution

  • These types are not a fixed size. They are the type that is at least the given size that will tend to be fastest.

    These types are defined in section 7.20.1.3 of the C standard:

    1 Each of the following types designates an integer type that is usually fastest to operate with among all integer types that have at least the specified width.

    2 The typedef name int_fastN_t designates the fastest signed integer type with a width of at least N. The typedef name uint_fastN_t designates the fastest unsigned integer type with a width of at least N.