Path: utzoo!attcan!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!husc6!tom!geoff From: geoff@tom.harvard.edu (Geoff Clemm) Newsgroups: comp.lang.c++ Subject: Re: Improved switch statement Message-ID: <901@husc6.harvard.edu> Date: 2 Jan 89 18:29:01 GMT References: <1031@uqvax.decnet.uq.oz> Sender: news@husc6.harvard.edu Reply-To: geoff@harvard.harvard.edu (Geoff Clemm) Organization: /etc/organization Lines: 25 In article <1031@uqvax.decnet.uq.oz> phcoates@uqvax.decnet.uq.oz writes: >In article <9276@ihlpb.ATT.COM> nevin1@ihlpb.ATT.COM(Nevin Liber) writes: >|... The only useful way to used the proposed >|change to the switch statement requires that I know exactly how it gets >|rewritten as an if-then-else chain, in which case I would rather use the >|if-then-else chain, since it is more 'self-documenting'. > ... >If so, then why bother to keep the switch statement at all? Must C++ be chained >to its ancestry if it is better that it fly free? Surely if the 'if' is better >then any program would be more 'self-documenting' if all such selections were >treated using 'if' constructs. The switch statement is used as a statement to the compiler that the following alternatives consist of mutually exclusive cases of a discrete type (such as integers and characters), which therefore can be implemented via a jump table. One advantage of a switch statement is that a compiler can tell you if you erroneously have two alternatives labelled with the same value. All of this silliness about "extending" the switch statement so that it becomes identical to an if-elseif chain, and then the compounded silliness of asking why then we have a switch statement is becoming excessive. Geoff Clemm