Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 alpha 4/3/85; site ukma.UUCP Path: utzoo!watmath!clyde!cbosgd!ukma!david From: david@ukma.UUCP (David Herron, NPR Lover) Newsgroups: net.lang.c Subject: Re: An amusing piece of code Message-ID: <3070@ukma.UUCP> Date: Sun, 6-Apr-86 13:05:10 EST Article-I.D.: ukma.3070 Posted: Sun Apr 6 13:05:10 1986 Date-Received: Wed, 9-Apr-86 20:29:04 EST References: <1370@ism780c.UUCP> Reply-To: david@ukma.UUCP (David Herron, NPR Lover) Organization: U of KY Mathematical Sciences Lines: 43 In article <1370@ism780c.UUCP> tim@ism780c.UUCP (Tim Smith) writes: >Here is an amusing piece of code that someone who wants to remain >annonymous invented. Good idea :-). > ... > switch ( thing ) { >case A: A-code; break; >case B: B-code; if ( 0 ) { >case C: C-code; if ( 0 ) { >case D: D-code; }} > BCD-common-code; break; >case E: E-code; > } > >Noone here has been able to come up with a reasonable style for this. The >example above is not to bad, but if B-code, C-code, etc, are complicated, >then it starts to get ugly. I don't like this either... it's not very straightforward, but ALSO, there's a potential problem I think. "case D:" exits TWO levels of context and never entered ANY, case C: exits TWO but only entered ONE. (Is this ever a problem? I can see that it "might" be, but I'm also sure that the PCC will run it fine.) What about: switch(thing) { case A: A-code; break; case B: B-code; goto BCD-common; case C: C-code; goto BCD-common; case D: D-code; BCD-common: BCD-code; break; case E: E-code; } I know, EVIL NASTY goto statements. But this is a limited local use of goto's and surely that should be allowable except for the most rabid of structurists. Especially if there is commentation pointing the reader toward BCD-common:. -- David Herron, cbosgd!ukma!david, david@UKMA.BITNET, david@uky.csnet