the C switch

Guy Harris guy at rlgvax.UUCP
Sun Mar 3 17:24:33 AEST 1985


> > Do any C compilers perform switch optimization? I.e. tradeoff cascaded if
> > for table lookup.
> 
> All the C compilers I am familiar with have about three different ways
> of generating code for a switch statement, in an attempt to optimize
> the size of the code vs. its speed.

Specifically, for a dense switch the VAX PCC generates a "casel" (indexed
branch) instruction.  For a sparse switch with a small number of cases, it
generates a cascaded "if".  For stuff in between, it either generates a linear
or hashed table search.  I believe the Ritchie PDP-11 C compiler generates
similar code; many other PCC implementations do also.

	Guy Harris
	{seismo,ihnp4,allegra}!rlgvax!guy
-- 
	Guy Harris
	{seismo,ihnp4,allegra}!rlgvax!guy



More information about the Comp.lang.c mailing list