Suppose you need to store an integer value which can range from zero to one million. Which is the smallest type you can use? There is no general rule; it depends on the C compiler and target machine. You can use the ‘MIN’ and ‘MAX’ macros in limits.h to determine which type will work.
Each signed integer type has a pair of macros which give the smallest and largest values that it can hold. Each unsigned integer type has one such macro, for the maximum value; the minimum value is, of course, zero.
The values of these macros are all integer constant expressions. The
‘MAX’ and ‘MIN’ macros for char
and short int
types have values of type int
. The ‘MAX’ and
‘MIN’ macros for the other types have values of the same type
described by the macro—thus, ULONG_MAX
has type
unsigned long int
.
SCHAR_MIN
signed char
.
SCHAR_MAX
UCHAR_MAX
signed char
and unsigned char
, respectively.
CHAR_MIN
char
.
It's equal to SCHAR_MIN
if char
is signed, or zero
otherwise.
CHAR_MAX
char
.
It's equal to SCHAR_MAX
if char
is signed, or
UCHAR_MAX
otherwise.
SHRT_MIN
signed short int
. On most machines that the GNU C library runs on,
short
integers are 16-bit quantities.
SHRT_MAX
USHRT_MAX
signed short int
and unsigned short int
,
respectively.
INT_MIN
signed int
. On most machines that the GNU C system runs on, an int
is
a 32-bit quantity.
INT_MAX
UINT_MAX
signed int
and the type unsigned int
.
LONG_MIN
signed long int
. On most machines that the GNU C system runs on, long
integers are 32-bit quantities, the same size as int
.
LONG_MAX
ULONG_MAX
signed long int
and unsigned long int
, respectively.
LONG_LONG_MIN
signed long long int
. On most machines that the GNU C system runs on,
long long
integers are 64-bit quantities.
LONG_LONG_MAX
ULONG_LONG_MAX
signed
long long int
and unsigned long long int
, respectively.
WCHAR_MAX
wchar_t
.
See Extended Char Intro.
The header file limits.h also defines some additional constants that parameterize various operating system and file system limits. These constants are described in System Configuration.