Jumping into blocks

chris at toram chris at toram
Sat Apr 26 10:45:00 AEST 1986


In article <737 at bentley.UUCP> kwh at bentley.UUCP (KW Heuer) writes:
>In article <275 at copper.UUCP> copper!stevesu (Steve Summit) writes:
>>Most people agree that goto's are pretty acceptable for handling
>>error conditions.  For instance:
>>
>>	[example deleted]
>
> ... But here's a real example I keep running into:
>
>	[example deleted]
>
>So, assuming that goatooze are acceptable for error handling, but jumping
>into a block is forbidden, what's the best way to write this?  Use two
>braches, and hide the common code at the bottom of main()?  Set an error
>flag and test it outside the while?  (Ugh, that requires an artificial
>boolean *and* a break statement.)  Make usage() a non-returning function
>instead of a label?  (My usual preference.)  Duplicate the code?

What's wrong with a flag and and "break"s?  "Break" after an error condition
is perfectly obvious, especially when the error test is right after the
loop.  Or duplicate the code, when it's so trivial.  What's a couple of
lines in the interest of readability?  Sure "goto"s can sometimes make
complicated things more readable (e.g., saving putting great chunks
of code in several nests of "if"s), but why on earth use it to make a
nice, straightforward error test obscure?



More information about the Comp.lang.c mailing list