FIX: M6110 Error When Using 'switch' Statement with /Oe

Last reviewed: September 18, 1997
Article ID: Q114075
7.00 | 1.00 MS-DOS | WINDOWS kbtool kbfixlist 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
    

SYMPTOMS

In certain cases the C/C++ compiler will generate incorrect code when the /Oe (Enable Global Register Allocation) optimization is used on source code which does floating point calculations before a switch statement. The compiler does not correctly generate code to clear the floating point stack after the floating point calculations have been performed. This causes a floating point stack overflow when the calculations are done repeatedly. When the program is run it will fail and display the following error message:

    run-time error M6110: MATH
    - floating-point error: stack overflow

The problem can be reproduced by building and running the sample code shown below.

RESOLUTION

To work around the problem, use the #pragma optimize() directive to disable /Oe for the function where the M6110 error occurs. This is indicated in the sample code below. Alternatively, the module containing the function could be compiled without the /Oe option.

STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed above. This problem was corrected in Visual C++ version 1.5.

Sample Code

/* Compile options needed: /Oe (or /O2, or /Ox, both include /Oe)
*/

#include <stdio.h>

/*    uncomment the #pragmas to correct the problem
#pragma optimize( "e", off )
*/

int main()
{
    int count;
    float flt1, flt2;

    for ( count = 1; count <= 50; count++ )
    {
        flt1 = 1.5F * count;
        flt2 = 2.0F * count;

        switch ( count )
        {
            default: printf( "In loop...\n" );
        }
    }

    printf( "Test was successful!\n" );
    return (int)( flt1 + flt2 );
}

/*
#pragma optimize( "e", on )
*/


Additional reference words: 7.00 8.00 1.00
KBCategory: kbtool kbfixlist kbbuglist
KBSubcategory: CLIss
Keywords : CLIss kb16bitonly kbbuglist kbfixlist kbtool
Version : 7.00 | 1.00
Platform : MS-DOS WINDOWS
Solution Type : kbfix


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.

Last reviewed: September 18, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.