problems/risks due to programming language
Richard O'keefe
ok at goanna.oz.au
Tue Feb 27 15:16:20 AEST 1990
In article <18033 at rpp386.cactus.org>, woody at rpp386.cactus.org (Woodrow Baker) writes:
> In article <2905 at goanna.oz.au>, ok at goanna.oz.au (Richard O'keefe) writes:
In fact the section which follows was QUOTED by me, not WRITTEN by me.
Please net.people, do take care with your attributions.
I _did_ write
> > (a) can't be done without introducing a goto or return, or rewriting
> > the code.
to which Woodrow Baker responded
> Wrong. you can always set a flag within the various cases and test it at
> the bottom or top of the loop. Yes this qualifies as re-writing the code.
It seems very odd to say "Wrong" and then admit two sentences later that
it isn't wrong at all. Look, you can program _any_ can of spaghetti you
like with _one_ loop, _one_ switch, and _one_ flag variable. The goal is
code that can be read and understood without too much strain; post hoc
flag variables are even worse for that than undisguised gotos.
In Ada, the method of quitting a loop early is the exit statement:
<Ada LRM 5.7 para 2>
exit_statement ::= EXIT [loop_name] [WHEN condition];
With no loop_name, it exits the innermost loop.
With a loop_name, it exits the loop labelled with that loop_name.
An equivalent for C would be a set of macros like
loop(LoopName)
break_loop(LoopName)
end_loop(LoopName)
which could be implemented thus:
#define loop(X) {
#define break_loop(X) goto X
#define end_loop(X) ;X:;}
This does amount to bending the syntax of C, but I think it may be an
excusable case. The proper nesting of these macros can be easily checked
by a simple tool, and it gives us a disciplined way of using the language
we already have.
More information about the Comp.lang.c
mailing list