6.17.14 Minimum-width Integer Constant Macros
Macros that expand to integer constants suitable for initializing objects that have
integer types corresponding to types defined in <stdint.h>
.
Include
<stdint.h>
Remarks
Each macro name corresponds to the <stdint.h>
type with a similar
name. The argument to these macros shall be a decimal, octal, or hexadecimal constant
with a value that does not exceed the limits for the corresponding type.
Macro | Expands to |
---|---|
INT8_C | A signed integer constant with the specified
argument value and type int_least8_t . |
INT16_C | A signed integer constant with the specified
argument value and type int_least16_t . |
INT24_C | A signed integer constant with the specified
argument value and type int_least24_t , (see Attention
note). |
INT32_C | A signed integer constant with the specified
argument value and type int_least32_t |
INT64_C | A signed integer constant with the specified
argument value and type int_least64_t , (see Attention
note). |
UINT8_C | An unsigned integer constant with the specified
argument value and type uint_least8_t . |
UINT16_C | An unsigned integer constant with the specified
argument value and type uint_least16_t . |
UINT24_C | An unsigned integer constant with the specified
argument value and type uint_least24_t , (see Attention
note). |
UINT32_C | An unsigned integer constant with the specified
argument value and type uint_least32_t . |
UINT64_C | An unsigned integer constant with the specified
argument value and type uint_least64_t , (see Attention
note). |
Example
#include <stdint.h>
#include <stdio.h>
#include <inttypes.h>
int
main(void)
{
uint_least64_t ref;
ref = 1 << (sizeof(int)*8);
printf("ref is %" PRIxLEAST64 " (oops)\n", ref);
ref = UINT64_C(1) << (sizeof(int)*8);
printf("ref is %" PRIxLEAST64 " (better)\n", ref);
}
Example Output
For builds where the int
type (being the type assigned to the constant
1
) is 16 bits wide.
ref is 0x0 (oops)
ref is 0x10000 (better)
For builds where the int
type is 32 bits wide.
ref is 0x0 (oops)
ref is 0x100000000 (better)