Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!cmcl2!rutgers!rochester!cornell!uw-beaver!tektronix!teklds!zeus!tekla!dant From: dant@tekla.TEK.COM (Dan Tilque;1893;92-789;LP=A;60HC) Newsgroups: comp.lang.c Subject: Re: goto's and switch statements -- mild proposal Message-ID: <2182@zeus.TEK.COM> Date: Tue, 11-Aug-87 05:54:33 EDT Article-I.D.: zeus.2182 Posted: Tue Aug 11 05:54:33 1987 Date-Received: Wed, 12-Aug-87 07:22:15 EDT References: <855@tjalk.cs.vu.nl> <2683@hoptoad.uucp> <916@haddock.ISC.COM> Sender: news@zeus.TEK.COM Reply-To: dant@tekla.UUCP (Dan Tilque) Organization: First National Security Trust Bar and Grill Lines: 54 >John Gilmore writes: >>What bothers me is that I can't say ["goto default" and "goto case N"]. Karl Heuer writes: >It's interesting that this restriction exists, in view of the oft-stated claim >that the reason that switch statements have automatic fallthrough (rather than >automatic breakswitch) is that "case labels are just like real labels". I would guess that the restriction is there to discourage the use of goto's. I've never thought of cases as labels, but then I've never used a label in C. Cases certainly don't have the same syntax as labels. > it should be illegal to fall >into a label (one must instead write "goto foo; foo:"); and switch statements >should automatically break at the end of each case (thus freeing the keyword >"break" for loop exit exclusively). Oh yes, this also requires a new notation >for multiple cases ("case '0'..'9':" or whatever). > I'd be hard put to come up with a better notation for: switch (c) { case CR: /* assume appropriate #defines */ case LF: case TAB: case ' ': /* whatever */ . . . These 4 values are not contiguous. On possibility is to separating them with commas: case CR, LF, TAB, ' ': which changes the meaning of the comma operator. Probably not a good idea. However, I agree that it's bad programming to have this kind of thing: case 'a': a = b + count; case 'b': count += 2; . . . Lint should definitely give warning since it's almost always the case that what's desired is a break before case 'b':. Also, one of my more frequent mistakes is leaving breaks out of switches. --- Dan Tilque dant@tekla.tek.com or dant@tekla.UUCP