Next: Floating Type Macros, Previous: Width of Type, Up: Data Type Measurements
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_MINsigned char.
SCHAR_MAXUCHAR_MAXsigned char and unsigned char, respectively.
CHAR_MINchar.
It's equal to SCHAR_MIN if char is signed, or zero
otherwise.
CHAR_MAXchar.
It's equal to SCHAR_MAX if char is signed, or
UCHAR_MAX otherwise.
SHRT_MINsigned short int. On most machines that the GNU C library runs on,
short integers are 16-bit quantities.
SHRT_MAXUSHRT_MAXsigned short int and unsigned short int,
respectively.
INT_MINsigned int. On most machines that the GNU C system runs on, an int is
a 32-bit quantity.
INT_MAXUINT_MAXsigned int and the type unsigned int.
LONG_MINsigned long int. On most machines that the GNU C system runs on, long
integers are 32-bit quantities, the same size as int.
LONG_MAXULONG_MAXsigned long int and unsigned long int, respectively.
LONG_LONG_MINsigned long long int. On most machines that the GNU C system runs on,
long long integers are 64-bit quantities.
LONG_LONG_MAXULONG_LONG_MAXsigned
long long int and unsigned long long int, respectively.
WCHAR_MAXwchar_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.