Switch statement: extra out-of-bounds code emitted

Chris Sears cbsears_sf@yahoo.com
Thu Dec 20 14:30:00 GMT 2001


Given a switch statement of the form:

  unsigned char i;

  switch ( i ) {
    case 0: funct0(); break;
    case 1: funct1(); break;
    ... 
    case 255: funct255(); break;
  }

bounds checking the index variable is unnecessary.
I did a little research and this was suggested in 1989
and again in 1997, not exactly qualifying as an FAQ.

Can someone comment on this?

Chris Sears

__________________________________________________
Do You Yahoo!?
Check out Yahoo! Shopping and Yahoo! Auctions for all of
your unique holiday gifts! Buy at http://shopping.yahoo.com
or bid at http://auctions.yahoo.com



More information about the Gcc mailing list