| The GNU C Library | www.imodulo.com · 2003-04-05 | ||
| [ Software | Documentation | Contact ] |
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_MINThis is the minimum value that can be represented by a signed char.
SCHAR_MAXUCHAR_MAXThese are the maximum values that can be represented by a signed char and unsigned char, respectively.
CHAR_MINThis is the minimum value that can be represented by a char. It's equal to SCHAR_MIN if char is signed, or zero otherwise.
CHAR_MAXThis is the maximum value that can be represented by a char. It's equal to SCHAR_MAX if char is signed, or UCHAR_MAX otherwise.
SHRT_MINThis is the minimum value that can be represented by a signed short int. On most machines that the GNU C library runs on, short integers are 16-bit quantities.
SHRT_MAXUSHRT_MAXThese are the maximum values that can be represented by a signed short int and unsigned short int, respectively.
INT_MINThis is the minimum value that can be represented by a signed int. On most machines that the GNU C system runs on, an int is a 32-bit quantity.
INT_MAXUINT_MAXThese are the maximum values that can be represented by, respectively, the type signed int and the type unsigned int.
LONG_MINThis is the minimum value that can be represented by a 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_MAXULONG_MAXThese are the maximum values that can be represented by a signed long int and unsigned long int, respectively.
LONG_LONG_MINThis is the minimum value that can be represented by a signed long long int. On most machines that the GNU C system runs on, long long integers are 64-bit quantities.
LONG_LONG_MAXULONG_LONG_MAXThese are the maximum values that can be represented by a signed long long int and unsigned long long int, respectively.
WCHAR_MAXThis is the maximum value that can be represented by a wchar_t. 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.
| © Free Software Foundation, Inc. |