The ANSI C committee requires that all C compilers document the system-dependent ranges of integer and floating-point types in order to help you write portable code. Table 14-2 contains a listing of the ANSI C-required integral definitions found in the LIMITS.H header file.
Table 14-2: Values defined in LIMITS.H (ANSI C)
Defined Type
Size
Description
#define CHAR_BIT
8
Number of bits in a char
#define CHAR_MAX
SCHAR_MAX
Maximum char value
#define CHAR_MIN
SCHAR_MIN
Minimum char value
#define INT_MAX
2147483647
Maximum (signed) int value
#define INT_MIN
(-2147483647 – 1)
Minimum (signed) int value
#define LONG_MAX
2147483647L
Maximum (signed) long value
#define LONG_MIN
(-2147483647L – 1)
Minimum (signed) long value
#define SCHAR_MAX
127
Maximum signedchar value
#define SCHAR_MIN
(-128)
Minimum signedchar value
#define SHRT_MAX
32767
Maximum (signed) short value
#define SHRT_MIN
(-32768)
Minimum (signed) short value
#define UCHAR_MAX
0xff
Maximum unsignedchar value
#define UINT_MAX
0xffffffff
Maximum unsignedint value
#define ULONG_MAX
0xffffffffUL
Maximum unsignedlong value
#define USHRT_MAX
0xffff
Maximum unsignedshort value
Program code can use these ranges to make certain that data will fit in the specified data type. For example, a VAX integer may be 4 bytes, while an older DOS-based integer is only 2. To solve this problem, the following code might be used:
if (PROGRAM_NEEDED_MAX > INT_MAX) pvoid = new llong_storage; else pvoid = new iinteger_storage;
Table 14-3 shows the ANSI C-required floating-point definitions.
Table 14-3: Values Defined in FLOAT.H(ANSI C)
Definition
Value
Comment
#define FLT_RADIX
2
Exponent radix
#define FLT_ROUNDS
1
Addition rounding: near
smallest such that 1.0+FLT_EPSILON != 1.0 #define FLT_EPSILON
1.192092896e-07F
smallest such that 1.0+DBL_EPSILON != 1.0 #define DBL_EPSILON
2.2204460492503131e-016
smallest such that 1.0+LDBL_EPSILON != 1.0 #define LDBL_EPSILON