Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!rutgers!gatech!hubcap!ncrcae!ncrlnk!uunet!auspex!guy From: guy@auspex.UUCP (Guy Harris) Newsgroups: comp.lang.c++ Subject: Re: Improved switch statement (was Re: goodbye cpp ???) Message-ID: <744@auspex.UUCP> Date: 17 Dec 88 21:14:15 GMT References: <6590072@hplsla.HP.COM> <1106@etive.ed.ac.uk> <33528@bbn.COM> <1907@ogccse.ogc.edu> <574@redsox.UUCP> <14104@oberon.USC.EDU> Reply-To: guy@auspex.UUCP (Guy Harris) Distribution: na Organization: Auspex Systems, Santa Clara Lines: 24 >This is useful only as syntactic sugar: the switch statement >in C/C++ does *not* compile into a series of > >if (expr == case1) ... else if (expr == case2) ... > >statements, as your suggestion implies. Instead, (in all the >implementations I've seen, anyway) Sorry, I've seen C implementations where the compiler chooses one of: 1) an "if" chain 2) a vectored jump 3) a table lookup with a vectored jump depending on the number of cases. One such implementation is PCC, upon which a boatload of UNIX C compilers are based. >The switch statement you suggest would (of necessity) compile into a bunch >of if()s, which is not really what switch was designed to do... "switch" was designed to switch among a set of several alternatives; if that can only be done by an "if" chain, well, that's life....