This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Switch statement: extra out-of-bounds code emitted
- From: Dale Johannesen <dalej at apple dot com>
- To: Chris Sears <cbsears_sf at yahoo dot com>
- Cc: Dale Johannesen <dalej at apple dot com>, gcc at gcc dot gnu dot org
- Date: Thu, 20 Dec 2001 14:29:48 -0800
- Subject: Re: Switch statement: extra out-of-bounds code emitted
On Thursday, December 20, 2001, at 02:17 PM, Chris Sears wrote:
>
> 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.
Perhaps more usefully,
switch ( i&7 ) { /* or i%8 */
case 0: case 1: case 2: case 3: /* case bodies omitted */
case 4: case 5: case 6: case 7:
}
could omit the bounds checks. This isn't dependent on the type of i.