Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site rlgvax.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!godot!harvard!seismo!rlgvax!guy From: guy@rlgvax.UUCP (Guy Harris) Newsgroups: net.lang.c Subject: Re: the C switch Message-ID: <549@rlgvax.UUCP> Date: Sun, 3-Mar-85 02:24:33 EST Article-I.D.: rlgvax.549 Posted: Sun Mar 3 02:24:33 1985 Date-Received: Mon, 4-Mar-85 08:23:44 EST References: <800006@acf4.UUCP> <8874@brl-tgr.ARPA> Organization: CCI Office Systems Group, Reston, VA Lines: 18 > > 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