Microsoft KB Archive/111767

From BetaArchive Wiki

BUG: Incorrect Code Generated for Long Constant

Q111767

7.00 | 1.00 1.50 MS-DOS | WINDOWS kbtool kbbuglist ---------------------------------------------------------------------- The information in this article applies to: - The Microsoft C/C++ Compiler (CL.EXE), included with: - Microsoft C/C++ for MS-DOS, version 7.0 - Microsoft Visual C++ for Windows, versions 1.0 and 1.5 ---------------------------------------------------------------------- SYMPTOMS ======== Incorrect 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 value where '*' 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. CAUSE ===== The compiler generates incorrect code only if the following conditions are met: - The fast compiler is used. Under debug mode, this is the default. - The code is compiled as a C++ module. - A long constant is used in a relational expression in a for or a while statement. - The long constant has a value greater than the range of integer values (greater than +32767 or less than -32768). RESOLUTION ========== To avoid the problem, you can do any of the following: - Compile without using the fast compiler (/f-). - Because the error occurs only with a signed long constant, either use a variable or an unsigned long constant. STATUS ====== Microsoft 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 INFORMATION ================ The 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 * * Compile this sample code as a .CPP file */ #include 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 KBCategory: kbtool kbbuglist KBSubcategory: CodeGen

Keywords : kb16bitonly
Issue type : kbbug
Technology : kbVCsearch kbAudDeveloper kbCVCComp


Last Reviewed: May 5, 2001
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.