KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q38026: Minimum Range Values in the Include File limits.h

Article: Q38026
Product(s): See article
Version(s): 5.10   | 5.10
Operating System(s): MS-DOS | OS/2
Keyword(s): ENDUSER | S_QUICKC | mspl13_c
Last Modified: 15-NOV-1988

Question:

Why is the minimum value of CHAR and INT off by one in the include
file limits.h?

Response:

This behavior occurs because there is no corresponding positive value
for the SIGNED CHAR's minimum value. For example, the range of a
SIGNED CHAR is -128 to 127. The range specified in limits.h is -127 to
127. The range of a signed int is -32768 to 32767, but limits.h
specifies the range as -32767 to 32767.

If you were to take the absolute value of -128 with the ABS() function,
you would expect to get +128. This is correct; however, you must
ensure that you store the result in a variable that has a storage
class that can represent the value.

For example, it does not make sense, and is not possible, to take the
absolute value of -128 and try and store it in a SIGNED CHAR. 127 is
the maximum positive value for a this storage class.

The return value from the ABS() function is undefined if you try
to store the result in a storage class that cannot represent the
value.

THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Copyright Microsoft Corporation 1986-2002.