Fixed-Width Types
Overview
Prior to C23, exact-width integer types were available. Since C23 bit-precise integer types have also been included.
Exact-Width
The <stdint.h> library contains exact-width integer types. These are aliases to types that represent an exact width and sign representation:
- If the type
uintN_tis provided, it is an unsigned integer type with exactlybits of width and precision. - If the type
intN_tis provided, is is signed, with two's complement representation, has a width of exactlybits and a precision of .
The C standard says these typedefs must be defined if they can be satisfied. Otherwise they may not exist.
Bit-Precise
Since C23, bit-precise integer types allow specifying quantities that should fit within a specified number of bits. The number of bits is provided as an argument to the _BitInt specifier.
Literal types may use case-insensitive suffix wb to specify signed bit-precise integer types. Likewise, case-insensitive suffix uwb specifies unsigned bit-precise integer types.
Since C23, additional bit operations have been made available in the <stdbit.h> header. These functions act on unsigned integer types.