Article View: comp.os.msdos.programmer
Article #855MSC 6.0 has trouble with 32-bit switch/case
From: David L. Huestis
Date: Mon, 24 Aug 1992 00:38
Date: Mon, 24 Aug 1992 00:38
66 lines
2299 bytes
2299 bytes
/* When Microsoft C 6.0 compiles the following simple program
the compiler gets confused in constructing the comparisons
for the 32-bit switch/case statements. It appears to use
the fact that B1, B2, and B3 all have the same value in the
high 16-bits, leading potentially to shorter faster code,
but it loses track of the logic/branching thread by subtracting
values from 'dx' rather than comparing. Compile with /Fc
Replacing the switch/case with if() statements leads to correct
execution.
The program gives the following results:
for A1 expected 0 got 0
for A2 expected 1 got 1
for A3 expected 2 got 2
for B1 expected 2 got 2
for B2 expected 1 got 3
for B3 expected 0 got 3
------------------------
David L. Huestis
SRI International
<huestis@mplvax.sri.com>
--------------------------------------------------------------------
*/
#include <stdio.h>
#define A1 0x0A0001UL
#define A2 0x0A0002UL
#define A3 0x0A0003UL
#define B1 0x0B0001UL
#define B2 0x0B0002UL
#define B3 0x0B0003UL
int tsw(unsigned long sw)
{
switch(sw)
{
case A1 : case B3 :
return( 0 ) ;
break ;
case A2 : case B2 :
return( 1 ) ;
break ;
case A3 : case B1 :
return( 2 ) ;
break ;
default :
break ;
}
return(3) ;
}
main()
{
printf("for A1 expected 0 got %d\n", tsw(A1) ) ;
printf("for A2 expected 1 got %d\n", tsw(A2) ) ;
printf("for A3 expected 2 got %d\n", tsw(A3) ) ;
printf("for B1 expected 2 got %d\n", tsw(B1) ) ;
printf("for B2 expected 1 got %d\n", tsw(B2) ) ;
printf("for B3 expected 0 got %d\n", tsw(B3) ) ;
}
Technical Details
Message-ID:
<Q7DCWI@MPLVAX.SRI.COM>Path:
arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!unix!MPLVAX.SRI.COM!HUESTISShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!unix!MPLVAX.SRI.COM!HUESTIS From: HUESTIS@MPLVAX.SRI.COM (David L. Huestis) Newsgroups: comp.os.msdos.programmer,comp.lang.c Subject: MSC 6.0 has trouble with 32-bit switch/case Message-ID: <Q7DCWI@MPLVAX.SRI.COM> Date: 24 Aug 92 00:38:37 GMT Sender: news@unix.SRI.COM Followup-To: comp.os.msdos.programmer Organization: Molecular Physics Laboratory, SRI International, Menlo Park, CA Lines: 66