This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Switch statement: extra out-of-bounds code emitted



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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]