ID: Q111767
7.00 | 1.00 1.50 MS-DOS | WINDOWS kbtool kbbuglist
The information in this article applies to:
- Microsoft C/C++ for MS-DOS, version 7.0
- Microsoft Visual C++ for Windows, versions 1.0 and 1.5
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.
The compiler generates incorrect code only if the following conditions are met:
To avoid the problem, you can do any of the following:
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.
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.
/* 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
KBCategory: kbtool kbbuglist
KBSubcategory: CodeGen
Keywords : kb16bitonly
Last Reviewed: July 23, 1997