DOCUMENT:Q320004 11-JUN-2002 [visualc] TITLE :BUG: "Fatal Error C1001" Err Msg Compiling Code with While Loop PRODUCT :Microsoft C Compiler PROD/VER:: OPER/SYS: KEYWORDS:kberrmsg kbCompiler ====================================================================== ------------------------------------------------------------------------------- The information in this article applies to: - The C/C++ Compiler (CL.EXE), used with: - Microsoft Visual C++.NET (2002) ------------------------------------------------------------------------------- SYMPTOMS ======== When you try to compile code that is similar to the sample code included in the "Steps to Reproduce the Problem" section of this article, you may receive the following error message: "fatal error C1001: INTERNAL COMPILER ERROR (compiler file 'f:\vs70builds\9466\vc\Compiler\Utc\src\P2\main.c', line 146)" CAUSE ===== This behavior occurs because the optimizing compiler cannot optimize the while loop. RESOLUTION ========== To work around the issue, use one of the following methods: - Turn off the /Og switch for the function by using the following command: #pragma optimize("g",off) -or- - Declare the function parameter start to be volatile. STATUS ====== Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. MORE INFORMATION ================ Steps to Reproduce the Problem ------------------------------ Try to compile the following code: //test.cpp // Compiler Option: cl /c /Og test.cpp union Pixel{ char code8; } ; struct RGB { double r; }; //#pragma optimize("g",off)//WORKAROUND 1 void func( char *start, char *end) //void func( volatile char *start, char *end) //WORKAROUND 2 { RGB map[256]; Pixel s[16]; while (start < end) { *start++ = s[(int)((map[*start].r))].code8; } } #pragma optimize("",on) //WORKAROUND 1 You receive the error message described in the "Symptoms" section of this article. Additional query words: Og ICE KbCpp KbNative KBUnmanaged ====================================================================== Keywords : kberrmsg kbCompiler Technology : kbVCsearch kbAudDeveloper kbCVCComp Version : : Issue type : kbbug Solution Type : kbpending ============================================================================= THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY. Copyright Microsoft Corporation 2002.