Fixed-width signed and unsigned integer types. More...
A width that is part of a contract belongs in a type, not in a comment. File formats, network protocols, atomic cells, and byte-order conversion all name an exact number of bits. The C++ fundamental types do not: int may be 16 or 32 bits, long may be 32 or 64. This group is the portable spelling of those widths.
Each name is a typedef for a fundamental type that has that width on the current platform. Pt::int32_t is a signed 32-bit integer; Pt::uint8_t is an unsigned 8-bit integer. The typedef may be int on one target and long on another. Code that uses the Pt name keeps the width without writing per-platform #if.
The signed and unsigned pairs are:
| int8_t | signed 8-bit integer | uint8_t | unsigned 8-bit integer |
| int16_t | signed 16-bit integer | uint16_t | unsigned 16-bit integer |
| int32_t | signed 32-bit integer | uint32_t | unsigned 32-bit integer |
| int64_t | signed 64-bit integer | uint64_t | unsigned 64-bit integer |
Use these types where the width is the contract. Use int or std::size_t where the platform's natural width is the contract. Byte-order conversion in Byte Order and the atomic cell in Atomic Operations are defined in terms of these widths.