Microsoft KB Archive/122542

= BUG: Incorrect Code for Loop with Known Value =

Article ID: 122542

Article Last Modified on 7/5/2005

-

APPLIES TO


 * Microsoft C/C++ Professional Development System 7.0
 * Microsoft Visual C++ 1.0 Professional Edition
 * Microsoft Visual C++ 1.5 Professional Edition
 * Microsoft Visual C++ 1.51
 * Microsoft Visual C++ 2.0 Professional Edition

-



This article was previously published under Q122542



SYMPTOMS
When you use the /Ox, /Og, /O1, or /02 optimizations with the 32-bit compiler or the /Ox and /Ol optimizations with the 16-bit compiler, incorrect code is generated for loops where the number of iterations is a known value. The loop is not executed.



RESOLUTION
Workarounds are:

 Remove the optimization from the command line. -or-

  Use the optimize pragma to disable optimizations for the function. Use: #pragma optimize ("",off) before the function call, and use: #pragma optimize ("",on) after the function call. 



STATUS
Microsoft has confirmed this to be a bug in the products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.



Sample Code to Reproduce Problem
/* Compile options needed: /*       32-bit compiler: /Ox, /Og, /O1, or /02 /*       16-bit compiler: /Ox or /Ol

/* This sample prints out 11 */


 * 1) include 

void main(void) {  int i = 500; loop: i++; if( i <= 10 ) goto loop; printf( "This should be 501: %d\n", i ); }

Additional query words: 1.00 1.50 1.51 2.00 7.00 8.00 8.00c 9.00

Keywords: KB122542

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.