C Standard Library

C - <stdint.h>



The C <stdint.h> header defines a set of integral type, along with macros specifying their limits and macro functions to create values of these types.

Note: The library <stdint.h> was a part of extension, adopted by ANSI in 2000, commonly referred to as C99.

C <stdint.h> Types

The following are typedefs of fundamental integral types or extended integral types.

Signed TypesUnsigned TypesDescription
int8_t
int16_t
int32_t
int64_t
uint8_t
uint16_t
uint32_t
uint64_t
Integer type with width of exactly 8, 16, 32 and 64 bits respectively.
With no padding bits.
For signed type, using 2's complement for negative values.
int_least8_t
int_least16_t
int_least32_t
int_least64_t
uint_least8_t
uint_least16_t
uint_least32_t
uint_least64_t
Smallest integer type with width of at least 8, 16, 32 and 64 bits respectively.
int_fast8_t
int_fast16_t
int_fast32_t
int_fast64_t
uint_fast8_t
uint_fast16_t
uint_fast32_t
uint_fast64_t
Fastest integer type with width of at least 8, 16, 32 and 64 bits respectively.
intmax_t uintmax_t Integer type with the maximum width supported.
intptr_t uintptr_t Integer type capable of holding a pointer.

C <stdint.h> Macros

The below mentioned macros are implementation-specific and defined with the #define directive. The table below shows the different macros in <stdint.h> header and their minimal or maximal values in all implementations.

Signed integers : minimum value

MacrosDescriptionValue
INT8_MINMinimum value of an object of type int8_t Exactly -27
INT16_MINMinimum value of an object of type int16_t Exactly -215
INT32_MINMinimum value of an object of type int32_t Exactly -231
INT64_MINMinimum value of an object of type int64_t Exactly -263
INT_LEAST8_MINMinimum value of an object of type int_least8_t -(27-1), or lower
INT_LEAST16_MINMinimum value of an object of type int_least16_t -(215-1), or lower
INT_LEAST32_MINMinimum value of an object of type int_least32_t -(231-1), or lower
INT_LEAST64_MINMinimum value of an object of type int_least64_t -(263-1), or lower
INT_FAST8_MINMinimum value of an object of type int_fast8_t -(27-1), or lower
INT_FAST16_MINMinimum value of an object of type int_fast16_t -(215-1), or lower
INT_FAST32_MINMinimum value of an object of type int_fast32_t -(231-1), or lower
INT_FAST64_MINMinimum value of an object of type int_fast64_t -(263-1), or lower
INTPTR_MINMinimum value of an object of type intptr_t -(215-1), or lower
INTMAX_MINMinimum value of an object of type intmax_t -(263-1), or lower

Signed integers : maximum value

MacrosDescriptionValue
INT8_MAXMaximum value of an object of type int8_t Exactly (27-1)
INT16_MAXMaximum value of an object of type int16_t Exactly (215-1)
INT32_MAXMaximum value of an object of type int32_t Exactly (231-1)
INT64_MAXMaximum value of an object of type int64_t Exactly (263-1)
INT_LEAST8_MAXMaximum value of an object of type int_least8_t (27-1), or higher
INT_LEAST16_MAXMaximum value of an object of type int_least16_t (215-1), or higher
INT_LEAST32_MAXMaximum value of an object of type int_least32_t (231-1), or higher
INT_LEAST64_MAXMaximum value of an object of type int_least64_t (263-1), or higher
INT_FAST8_MAXMaximum value of an object of type int_fast8_t (27-1), or higher
INT_FAST16_MAXMaximum value of an object of type int_fast16_t (215-1), or higher
INT_FAST32_MAXMaximum value of an object of type int_fast32_t (231-1), or higher
INT_FAST64_MAXMaximum value of an object of type int_fast64_t (263-1), or higher
INTPTR_MAXMaximum value of an object of type intptr_t (215-1), or higher
INTMAX_MAXMaximum value of an object of type intmax_t (263-1), or higher

Unsigned integers : maximum value

MacrosDescriptionValue
UINT8_MAXMaximum value of an object of type uint8_t Exactly (28-1)
UINT16_MAXMaximum value of an object of type uint16_t Exactly (216-1)
UINT32_MAXMaximum value of an object of type uint32_t Exactly (232-1)
UINT64_MAXMaximum value of an object of type uint64_t Exactly (264-1)
UINT_LEAST8_MAXMaximum value of an object of type uint_least8_t (28-1), or higher
UINT_LEAST16_MAXMaximum value of an object of type uint_least16_t (216-1), or higher
UINT_LEAST32_MAXMaximum value of an object of type uint_least32_t (232-1), or higher
UINT_LEAST64_MAXMaximum value of an object of type uint_least64_t (264-1), or higher
UINT_FAST8_MAXMaximum value of an object of type uint_fast8_t (28-1), or higher
UINT_FAST16_MAXMaximum value of an object of type uint_fast16_t (216-1), or higher
UINT_FAST32_MAXMaximum value of an object of type uint_fast32_t (232-1), or higher
UINT_FAST64_MAXMaximum value of an object of type uint_fast64_t (264-1), or higher
UINTPTR_MAXMaximum value of an object of type uintptr_t (216-1), or higher
UINTMAX_MAXMaximum value of an object of type uintmax_t (264-1), or higher

Limits of other types

MacrosDescriptionValue
SIZE_MAX (C99)Maximum value of an object of type size_t(264-1), or higher
PTRDIFF_MIN (C99)Minimum value of an object of type ptrdiff_t-(216-1), or lower
PTRDIFF_MAX (C99)Maximum value of an object of type ptrdiff_t(216-1), or higher
SIG_ATOMIC_MIN (C99)Minimum value of an object of type sig_atomic_tIf sig_atomic_t is signed: -127, or lower
If sig_atomic_t is unsigned: 0
SIG_ATOMIC_MAX (C99)Maximum value of an object of type sig_atomic_tIf sig_atomic_t is signed: 127, or higher
If sig_atomic_t is unsigned: 255, or higher
WCHAR_MIN (C99)Minimum value of an object of wchar_t typeIf wchar_t is signed: -127, or lower
If wchar_t is unsigned: 0
WCHAR_MAX (C99)Maximum value of an object of wchar_t typeIf wchar_t is signed: 127, or higher
If wchar_t is unsigned: 255, or higher
WINT_MIN (C99)Minimum value of an object of wint_t typeIf wint_t is signed: -32767, or lower
If wint_t is unsigned: 0
WINT_MAX (C99)Maximum value of an object of wint_t typeIf wint_t is signed: 32767, or higher
If wint_t is unsigned: 65535, or higher

Function-like macros

MacrosDescription
INT8_Cexpands to a value of type int_least8_t
INT16_Cexpands to a value of type int_least16_t
INT32_Cexpands to a value of type int_least32_t
INT64_Cexpands to a value of type int_least64_t
UINT8_Cexpands to a value of type uint_least8_t
UINT16_Cexpands to a value of type uint_least16_t
UINT32_Cexpands to a value of type uint_least32_t
UINT64_Cexpands to a value of type uint_least64_t
INTMAX_Cexpands to a value of type intmax_t
UINTMAX_Cexpands to a value of type uintmax_t

Example:

The example below describes the working of macros constant of C <stdint.h> library.

#include <stdio.h>
#include <stdint.h>

int main (){
  //using int_least16_t type
  int_least16_t x = 10;

  //displaying maximum and minimum value
  printf("INT16_MIN: %d\n", INT16_MIN);
  printf("INT16_MAX: %d\n", INT16_MAX); 
  printf("UINT16_MAX: %d\n", UINT16_MAX); 
  printf("INT_LEAST32_MIN: %d\n", INT_LEAST32_MIN);
  printf("INT_LEAST32_MAX: %d\n", INT_LEAST32_MAX);

  return 0;
}

The output of the above code is machine dependent. One of the possible output could be:

INT16_MIN: -32768
INT16_MAX: 32767
UINT16_MAX: 65535
INT_LEAST32_MIN: -2147483648
INT_LEAST32_MAX: 2147483647