Fixed-Size Integers

Fixed-width signed and unsigned integer types. More...

Typedefs

typedef int_type int8_t
 Signed 8-bit integer type.
typedef uint_type uint8_t
 Unsigned 8-bit integer type.
typedef int_type int16_t
 Signed 16-bit integer type.
typedef uint_type uint16_t
 Unsigned 16-bit integer type.
typedef int_type int32_t
 Signed 32-bit integer type.
typedef uint_type uint32_t
 Unsigned 32-bit integer type.
typedef int_type int64_t
 Signed 64-bit integer type.
typedef uint_type uint64_t
 Unsigned 64-bit integer type.

Detailed Description

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_tsigned 8-bit integeruint8_tunsigned 8-bit integer
int16_tsigned 16-bit integeruint16_tunsigned 16-bit integer
int32_tsigned 32-bit integeruint32_tunsigned 32-bit integer
int64_tsigned 64-bit integeruint64_tunsigned 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.