C9203003: C 6.x May Generate Bad Code on Switch Statement

ID Number: Q81542

6.00 6.00a 6.00ax | 6.00 6.00a

MS-DOS | OS/2

buglist6.00 buglist6.00a buglist6.00ax fixlist7.00

Summary:

PROBLEM ID: C9203003

SYMPTOMS

The Microsoft C Compiler versions 6.0, 6.0a, and 6.0ax may

generate incorrect code for a switch statement containing a case

with the value -32767.

RESOLUTION

This error may be eliminated with one of the following workarounds:

1. Compile with /qc.

-or-

2. In the example below, change i to a negative integer.

-or-

3. In the example below, take the comments out of the MISSING case.

STATUS

Microsoft has confirmed this to be a problem in versions 6.0, 6.0a,

and 6.0ax. This problem was corrected in C/C++ version 7.0.

More Information:

The sample code below switches to the wrong case statement and prints

"INVALID case: i = 120".

Sample Code

-----------

/* Compile options needed: none

*/

#include <stdio.h>

#define MISSING -32766

#define INVALID -32767

void main (void)

{

short i = 120;

switch( i )

{

case MISSING:

//printf( "MISSING case: i = %d\n", i ); // Uncomment for

//break; // resolution #3.

case INVALID:

printf( "INVALID case: i = %d\n", i );

break;

default:

printf( "DEFAULT case: i = %d\n", i );

break;

}

}

Additional reference words: 6.00 6.00a 6.00ax