Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!elroy!spl1!laidbak!daveb From: daveb@laidbak.UUCP (Dave Burton) Newsgroups: comp.lang.c Subject: Re: gotos Message-ID: <1412@laidbak.UUCP> Date: 18 Apr 88 14:11:58 GMT References: <1988Apr8.183815.3187@utzoo.uucp> <449@goofy.megatest.UUCP> <1988Apr11.201934.20594@utzoo.uucp> <748@l.cc.purdue.edu> <3470@bun Reply-To: daveb@laidbak.UUCP (Dave Burton) Organization: is pretty bad/My method of Lines: 54 In article <3470@bunker.UUCP> garys@bunker.UUCP (Gary M. Samuelson) writes: |In article <748@l.cc.purdue.edu> cik@l.cc.purdue.edu (Herman Rubin) writes: |>Here is a challenge to the denigrators of goto. |Case 5: | b >>= g16; | m |= b; | x = *(--geom); | if (TEST) { | if (ODD(x)) Case2(); | else Case1(); | } else { | g4 = (x+1)/2; | if (ODD(x)) Case3(); | else Case4(); | } Gary - this is no flame in your direction (Herman deserves all he receives for writing code like he challenged with). With the type of logic the original code fragment was using, your modification would be deep down in nested and re-nested function calls before you could say "Memory fault -- core dumped" :-). About the only way (from the too little context given by Herman) that I know to clean up his code without gotos is to use states. The overhead is very small, typically just one extra test per 'loop'. Maybe something like: enum calcs { start, state0, ..., state5 } state = start; enum calcs compute(); switch (state) { case start: state = compute(); break; case state0: x = 1+2; state = CRAP(x) ? state1 : state2; break; ... case state5: b >>= g16; m |= b; x = *(--geom); if (TEST) { state = ODD(x) ? state2 : state1; } else { g4 = (x+1)/2; state = ODD(x) ? state3 : state4; } break; } -- --------------------"Well, it looked good when I wrote it"--------------------- Verbal: Dave Burton Net: ...!ihnp4!laidbak!daveb V-MAIL: (312) 505-9100 x325 USSnail: 1901 N. Naper Blvd. #include Naperville, IL 60540