Fixed Width Integer Types
The C99 standard includes definitions of several new integer types to enhance the portability of programs. The already available basic integer types were deemed insufficient, because their actual sizes are implementation defined and may vary across different systems. The new types are especially useful in embedded environments where hardware supports usually only several types and that support varies from system to system. All new types are defined in inttypes.h
header (cinttypes
header in C++) and also are available at stdint.h
header (cstdint
header in C++). The types can be grouped into the following categories:
- Exact width integer types which are guaranteed to have the same number N of bits across all implementations. Included only if it is available in the implementation.
- Least width integer types which are guaranteed to be the smallest type available in the implementation, that has at least specified number N of bits. Guaranteed to be specified for at least N=8,16,32,64.
- Fastest integer types which are guaranteed to be the fastest integer type available in the implementation, that has at least specified number N of bits. Guaranteed to be specified for at least N=8,16,32,64.
- Pointer integer types which are guaranteed to be able to hold a pointer
- Maximum width integer types which are guaranteed to be the largest integer type in the implementation
The following table summarizes the types and the interface to acquire the implementation details (N refers to the number of bits):
Type category | Signed types | Unsigned types | ||||
---|---|---|---|---|---|---|
Type | Minimum value | Maximum value | Type | Minimum value | Maximum value | |
Exact width | intN_t |
INTN_MIN |
INTN_MAX |
uintN_t |
0 | UINTN_MAX |
Least width | int_leastN_t |
INT_LEASTN_MIN |
INT_LEASTN_MAX |
uint_leastN_t |
0 | UINT_LEASTN_MAX |
Fastest | int_fastN_t |
INT_FASTN_MIN |
INT_FASTN_MAX |
uint_fastN_t |
0 | UINT_FASTN_MAX |
Pointer | intptr_t |
INTPTR_MIN |
INTPTR_MAX |
uintptr_t |
0 | UINTPTR_MAX |
Maximum width | intmax_t |
INTMAX_MIN |
INTMAX_MAX |
uintmax_t |
0 | UINTMAX_MAX |
Read more about this topic: C Data Types
Famous quotes containing the words fixed, width and/or types:
“These earthly godfathers of Heavens lights,
That give a name to every fixed star,
Have no more profit of their shining nights
Than those that walk and wot not what they are.”
—William Shakespeare (15641616)
“Newly stumbling to and fro
All they find, outside the fold,
Is a wretched width of cold.”
—Philip Larkin (19221986)
“... there are two types of happiness and I have chosen that of the murderers. For I am happy. There was a time when I thought I had reached the limit of distress. Beyond that limit, there is a sterile and magnificent happiness.”
—Albert Camus (19131960)