Article ID: 320003
Article Last Modified on 7/5/2005
APPLIES TO
- Microsoft Visual C++ .NET 2002 Standard Edition
This article was previously published under Q320003
SYMPTOMS
If you compile code similar to that shown in the "Steps to Reproduce the Behavior" section, you may receive the following error message:
CAUSE
The Optimizing Compiler is trying to unroll the for loop, and failing.
RESOLUTION
Use either one of the following workarounds:
Turn off the /Og switch for the function by using:
#pragma optimize("g",off)
-or-
- Declare the local variables (s or r) volatile.
STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in Microsoft Visual C++ .NET (2003).
MORE INFORMATION
Steps to Reproduce the Behavior
To reproduce the problem, run the following code sample:
//test.cpp // Compiler Option: cl /c /Og test.cpp struct A{double x;}; struct B{ unsigned int size; A* samples; }; //#pragma optimize("g",off)//WORKAROUND 1 void test(B* pB) { int s; //volatile int s; //WORKAROUND 2 int r; s = pB->size; for(r = (pB->size - 1);s < r;r--){ pB->samples[r].x = pB->samples[r - 1].x; } } //#pragma optimize("",on) //WORKAROUND 1
Additional query words: Og ICE KbCpp KbNative KBUnmanaged
Keywords: kbbug kbfix kbpending kbcompiler KB320003