Path: utzoo!mnetor!uunet!husc6!linus!philabs!micomvax!ray From: ray@micomvax.UUCP (Ray Dunn) Newsgroups: comp.lang.c Subject: The D Programming Language: switches Message-ID: <941@micomvax.UUCP> Date: 15 Mar 88 21:10:15 GMT References: <222965b9@ralf.home> Reply-To: ray@micomvax.UUCP (Ray Dunn) Organization: Philips Electronics Ltd. (TDS - Montreal) St. Laurent P.Q., Canada Lines: 56 [References to various postings giving various proposed incarnations of switch syntax ommitted] My 2-penny-worth is that the switch statement is anyway too restrictive with its integer constant expression values, and that making a special case [pun not intended] of this was Not Really Worthwhile. Case statements should just be generalised into a "shorthand" way of stating if...elseif...elseif...else... So, (simplified to give jist rather than be definitive): switch { [declaration] case (expression): . [statement] . case (expression): . [statement] . default: . [statement] . } Where the expression in each "case (expression)" is a full boolean expression as in "if (expression)". There could of course be a (bad) argument to say that if "switch {" appears as "switch (expression) {" then the previous constant expression meaning of the switch is used - pretend I didn't suggest that. Automatic fallthrough should *not* take place, and the common fallthrough requirement of: case 1: case 2: case 3: becomes a simple 'or'ed boolean expression. Compilers can easily generate just as "efficient" code when only constant expression values are involved (MSC 4.0 seems to generate worse code when you use a case statement than when you use an if...else if...else... sequence!). [God! I've just realized that this is aprroximately the way case statements are defined in that *wonderful* (:-) language dBaseIII - so, I know, I've just lost any credibility I may have had!!] Ray Dunn. ..{philabs, mnetor, musocs}!micomvax!ray