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

ID: Q114075

7.00 | 1.00 MS-DOS | WINDOWS kbtool kbfixlist kbbuglist

The information in this article applies to:

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          : kb16bitonly kbCompiler kbbuglist kbfixlist
Version           : 7.00   | 1.00
Platform          : MS-DOS WINDOWS
Solution Type     : kbfix

Last Reviewed: September 22, 1997