The information in this article applies to:
SYMPTOMSThe compiler error:
-or- may be caused by an integer expression in the subscript of an array. If the expression evaluates to greater than INT_MAX, as defined in limits.h, its value becomes negative, thus causing the aforementioned error. For the 16- bit compilers, INT_MAX equals 32767; for 32-bit compilers, INT_MAX equals 2,147,483,647. CAUSEThis is correct and expected behavior for the Microsoft C Compiler because the evaluation of integer expressions is done using integer math. In some cases, integer math produces an incorrect result because the value of the expression is larger than an integer. RESOLUTION
16-bit: To work around this situation, add an uppercase (or lowercase) "L"
to one of the terms of the expression. This will force the compiler to
evaluate the expression using long math which is less likely to overflow.
MORE INFORMATIONIf the sample code below is compiled with C/C++ version 7.0 or Visual C++ for Windows, the following error message will be generated: Moreover, if the warning level is set to 2 or above, the following warning message will also be generated: To eliminate the error, add "L" to one of the terms to indicate it is a long constant. For example:
Sample Code
Visual C++ 32-bit edition will not generate an error with the above Sample
Code because integers are 4 bytes instead of 2 bytes and the limit for the
subscript is 2,147,483,647. However, if we include LIMITS.H and use INT_MAX
+ 2 as the size of the array, we can generate the desired error.
Additional query words: 8.00 8.00c 9.00 9.10
Keywords : kbCompiler kbVC100 kbVC150 kbVC151 kbVC200 kbVC210 kbVC400 kbVC500 |
Last Reviewed: July 6, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |