Path: utzoo!attcan!utgpu!watmath!watdragon!akwright From: akwright@watdragon.waterloo.edu (Andrew K. Wright) Newsgroups: comp.lang.c++ Subject: Re: goodbye cpp ??? Message-ID: <10468@watdragon.waterloo.edu> Date: 16 Dec 88 13:44:41 GMT References: <6590072@hplsla.HP.COM> <1106@etive.ed.ac.uk> <33528@bbn.COM> Reply-To: akwright@watdragon.waterloo.edu (Andrew K. Wright) Organization: U. of Waterloo, Ontario Lines: 44 In article <33528@bbn.COM> lpringle@labs-n.bbn.com (Lewis G. Pringle) writes: ... example omitted >This example reminds me of a suggestion for an extention to C++. The problem >with the above code is that switch statements require the cases to be integer >constants - though there is really no good reason for this. ... >When c++ sees a switch statement, it could generate the skip-chain >of if-then-elseifs from that, so long as the argument to the switch >and the cases where all =='able. (As an optimization - of course - >when the cases are all constant it could just output the C switch statement >as-is.) There is one crucial difference between an if-else chain and a C switch: the case arms of a C switch are checked for duplication. Allowing switch to operate on data of any type makes this duplication check impossible at compile time. An idea i had a few years ago, but have never had the time to test, is this: a switch executes *all* cases which match. This could be quite useful in many cases, altho code generation for it is a bit more complex. It is a bit difficult to fit into C, since C cases dont really have an "endcase". But you can imagine one, and consider: switch( x ) { case 1: case 2: code for x == 1 or 2; endcase; case 2: code for x == 2 only; endcase; case 1: case 2: case 3: code for x == 1, 2, or 3; endcase; } To code this example in ordinary C you must use two switches (or some ifs). A C switch allows the flow of control from two case arms to merge, but not to branch. this construct allows both merging and branching. Wierd? maybe. if your suggestion was a kitchen sink, this is a veritable jacuzzi. Andrew K. Wright akwright@watmath.waterloo.edu CS Dept., University of Waterloo, Ont., Canada.