Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!husc6!redsox!campbell From: campbell@redsox.UUCP (Larry Campbell) Newsgroups: comp.lang.c++ Subject: Re: Improved switch statement (was Re: goodbye cpp ???) Message-ID: <575@redsox.UUCP> Date: 17 Dec 88 16:09:24 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: campbell@redsox.UUCP (Larry Campbell) Distribution: na Organization: The Boston Software Works, Inc. Lines: 39 In article <14104@oberon.USC.EDU> english@stromboli.usc.edu (Joe English) writes: }[code fragment using switch(), equivalent to if (flag1)...else if (flag2)... ] } }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) it does a vectored jump, or if the }(case_i) values are not close together (e.g., case 10: ... case }100:... case 1000:...) into a table lookup with a vectored jump ... So what? The compiler could still generate the vectored jump or table lookup if the type of the argument was an integer or enum, and you'd still have your precious efficiency. I don't think it's reasonable to hamstring the language in order to make it easier for people to hack compilers together. My point, by which I stand, is that the new behavior is: 1) Consistent with the old behavior 2) Completely backward compatible 3) Provides a useful facility which can clarify code significantly 4) Can generate the same efficient code in the old (integer) case 5) Is not even a new feature, per se, but merely the relaxation of an annoying restriction, which restriction was probably initially made in order to simplify compiler construction Remember, we're talking about C++, not C, so we're not -- yet -- I hope -- constrained by the weight of years of tradition, inertia, and laziness. -- Larry Campbell The Boston Software Works, Inc. campbell@bsw.com 120 Fulton Street wjh12!redsox!campbell Boston, MA 02146