Minimum Range Values in the Include File LIMITS.H

ID: Q38026

5.10 6.00 6.00a 6.00ax 7.00 | 5.10 6.00 6.00a | 1.00 1.50

MS-DOS                      | OS/2            | WINDOWS
kbtool kbfasttip

The information in this article applies to:

The values of SCHAR_MIN, SHRT_MIN, and INT_MIN are off by one in the include file LIMITS.H.

For example, even though a signed char can be used to represent values in the range of -128 to 127, LIMITS.H defines SCHAR_MIN, the minimum signed char value, as -127. This is done for ANSI conformance.

Section 2.2.4.2.1 of the ANSI specification for the C programming language specifies the minimum values for these integral types. The minimum values chosen were selected to accommodate compiler implementations, which use one's complement or sign-magnitude as well those implementations that use two's complement.

The values for SCHAR_MIN, SHRT_MIN, and INT_MIN in the file LIMITS.H supplied with Visual C++ 32-bit Edition, are not off by one. For example, the value of SCHAR_MIN is -128. This allows access to the full range of values that can be represented by the type. This implementation is still ANSI-compliant because section 2.2.4.2.1 of the ANSI specification outlines the following when discussing the sizes of the integral types specified in LIMITS.H:

   ... Their implementation defined values shall be equal or greater
   in magnitude (absolute value) to those shown, with the same sign.

Additional reference words: kbinf 1.00 1.50 5.10 6.00 6.00a 6.00ax 7.00 KBCategory: kbtool kbfasttip KBSubcategory: TlsMisc Keywords : kb16bitonly

Last Reviewed: July 18, 1997