Fixed-size integer types

  1. Courses


  2. Complete C++ Course


  3. The C Standard Library


  4. Fixed-size integer types

Integer types

At the beginning of this course, we saw the signed and unsigned integer primitives (char, short, int, long, unsigned, unsigned long...). The size (In bytes) or those variable types is not fixed and may vary depending on the compiler used. The header <stdint.h> of the C Standard Library defines integer types with fixed sizes and integer types that are of a minimum size.


The types defined in the header <stdint.h> are not actually types, but rather typedefs of signed/unsigned integer primitives.

For example, int16_t is a typedef of an integer type that is guaranteed to weight 2 octets (16 bits). A compiler might define int_16t to be a typedef of the type short if the compiler defines the type short as a 16 bits integer. An other compiler with which the type int is coded using 16 bits might make int_16t a typedef of int.

Note that the typedefs of fixed-size integers defined in the header <stdint.h> are optional. If the machine the compiler compiles to does not natively support one of those integer sizes, the typedef of the integer of that size will not be defined (Thus we will not be able to use it). For example, a processor which byte size is 9 bits would not support integers made of 8 bits, because, remember, a byte is the smallest amount of memory a processor can natively work with. If the smallest unit of memory it can directly handle is 9 bits, it obviously can not directly handle 8 bits memory units.

Integer types with fixed-sizes

Here are the aliases of the fixed-size integers:

Number of bitsSignedUnsigned
Maximum natively supportedintmax_tuintmax_t

Smallest types with a minimum size

The header <stdint.h> also defines two other groups of integer aliases. Those groups do not define fixed-size integers, but define integers which are guaranteed to be of a minimum size. The first group defines integers that are at least of the specified size and if the machine does not support integers of that size, the typedef is linked to the integer type with the closest size that is at least of the size specified.

Here are the aliases of that group:

Minimum size (In bits)SignedUnsigned

Types optimized for performance

The next group defines aliases to integers that are at least of the specified size, but that are not necessarily the closest, but rather the fastest integer type that is at least of the specified size. Let us say we define a variable using the typedef of that group for an integer of at least 32 bits. If the machine supports 32 bits integers, but executes instructions faster when using 64 bits integers, the alias will point to a 64 bits integer.

Here are the aliases of that group:

Minimum size (In bits)SignedUnsigned