BUG: Incorrect Code Generated for Long ConstantLast reviewed: July 22, 1997Article ID: Q111767 |
7.00 | 1.00 1.50
MS-DOS | WINDOWS
kbtool kbbuglist
The information in this article applies to:
SYMPTOMSIncorrect code is generated when using a long constant in a conditional expression in a for or a while statement. If attempting to compile using Microsoft Visual C++ versions 1.0 or 1.5, the following warning may be generated under warning level 2 or higher
warning C4309: '*' : truncation of constant valuewhere '*' is the relational operator used in the condition. There is no warning or error message with version 7.0 of the C/C++ compiler; however, the problem still occurs.
CAUSEThe compiler generates incorrect code only if the following conditions are met:
RESOLUTIONTo avoid the problem, you can do any of the following:
STATUSMicrosoft has confirmed this to be a problem in C/C++ version 7.0 and Visual C++ for Windows, versions 1.0 and 1.5. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available. This is not a problem in the 32-bit compilers.
MORE INFORMATIONThe following sample code will produce a warning at the line indicated when compiled with Visual C++ version 1.0 or 1.5 under warning level 2 or above. No warning will be generated with version 7.0. In either case, the body of the for loop will not be executed.
Sample Code
/* Compile options needed: /f and </W3 or /W4>* * Compile this sample code as a .CPP file */ #include <stdio.h>const long bignum = 131072L;
void main(){ for (long l = 0L; l < bignum; l++) { printf("%ld\n",l); // This line never executes. } // warning C4309: '<' : truncation of constant value } |
Additional reference words: 1.00 1.50 7.00 8.00 8.00c
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |