BUG: Bad Code for Case 0xFFFFFFFF in Switch on Unsigned Long

Last reviewed: July 22, 1997
Article ID: Q113117
7.00 | 1.00 1.50 MS-DOS | WINDOWS kbtool 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 and 1.5
    

SYMPTOMS

The compiler generates incorrect code for a switch statement on an unsigned long variable involving a case 0xFFFFFFFF. The generated code may crash or behave unpredictably if the code is compiled with the /f- compiler switch.

CAUSE

In switch statements involving a case 0xFFFFFFFF or case -1L, the compiler may generate incorrect code when the /f- option is used.

RESOLUTION

To avoid the problem, one option is to use the /f compiler switch instead of the /f- compiler switch. Another option is to change the switch statement to switch on a signed long instead of an unsigned long.

STATUS

Microsoft has confirmed this to be a problem in C/C++ for MS-DOS versions 7.0, 8.0, and 8.0c. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

Sample Code

/* Compile options needed: /f-
*/

#include <stdio.h>

void func (unsigned long dVar)
{
    switch (dVar)
    {
    case 0:
        printf ("Error - switch on 0xFFFFFFFF went to 0\n");
        break;
    case 0xFFFFFFFFUL:
        printf ("Switch statement was successful\n");
        break;
    default:
        printf ("Error - switch on 0xFFFFFFFF went to default\n");
        break;
    }
}

void main ()
{
    func (0xFFFFFFFFUL);
}


Additional reference words: 1.00 1.50 7.00 8.00 8.00c fast compile
KBCategory: kbtool kbbuglist
KBSubcategory: CodeGen
Keywords : kb16bitonly


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: July 22, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.