Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83 based; site homxb.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!homxb!gemini From: gemini@homxb.UUCP (Rick Richardson) Newsgroups: net.lang.c Subject: Re: An amusing piece of code Message-ID: <1416@homxb.UUCP> Date: Wed, 9-Apr-86 21:50:31 EST Article-I.D.: homxb.1416 Posted: Wed Apr 9 21:50:31 1986 Date-Received: Fri, 11-Apr-86 01:03:35 EST References: <1370@ism780c.UUCP> <2600044@ccvaxa>, <638@ho95e.UUCP> Organization: PC Research, Inc. Lines: 40 The ongoing debate (?): > switch ( thing ) { > case A: A-code; break; > case B: B-code; goto BCDcode; > case C: C-code; goto BCDcode; > case D: D-code; goto BCDcode; > BCDcode: BCD-common-code; break; > case E: E-code; break; > } - VERSUS - > switch ( thing ) { > case A: A-code; BCD_later_flag = FALSE; break > case B: B-code; BCD_later_flag = TRUE; break > case C: C-code; BCD_later_flag = TRUE; break > case D: D-code; BCD_later_flag = TRUE; break > case E: E-code; BCD_later_flag = FALSE; break > default: default-code; BCD_later_flag = FALSE; > } > if (BCD_later_flag) { > whetever(); > } Essentially, both pieces of code are equivalent in "confusion factor". The goto version leaves the reader wondering "goto WHERE?", the BCD_later version leaves the reader wondering "BCD how much LATER?". Six one way, half a dozen the other. Me? I'll either put BCD in a function, or, if I don't think I want to incur the function call overhead, will use the goto version. After all, if I didn't want to do a function call then I'm probably after every last cycle I can squeeze out of the code, in which case its cheaper to just jump to where I want to go, rather than setting a flag. Then again, there's always MACRO's to make it look like the function call version without the subroutine call overhead... ...I'm easy, as long as it works. Rick Richardson, PC Research, Inc. (201) 922-1134, (201) 834-1378 @ AT&T-CP ..!ihnp4!castor!{rer,pcrat!rer} <--Replies to here, not to homxb!gemini, please.