hashing external names & other goodies.
Mark Terribile
mat at hou4b.UUCP
Fri Jan 11 04:15:29 AEST 1985
> -- are break (n) and continue (n) in the ANSI Proposed Standard yet? (If
> you couldn't guess, the one breaks (n) levels of code structures -- case's,
> while's, etc. -- while the other continues with the n'th enclosing loop.)
> Yes, I recognise the existence of setjmp() and longjmp(), but get queasy at
> the thought of any kind of jump.
I hope these NEVER get in! This is a great way to write fragile code, and
there is a MUCH more durable way to get what you are trying to get
Why is it fragile? Well, it's easy to break it accidentally when
you rework code.
while( ... )
switch( ... )
{
case ..:
... lots of code ...
break 2;
... lots more code ...
break;
case ..:
...
}
What happens when that ``lots of ... lots more code'' gets surrounded by
another loop or another switch in the course of the program's evolution?
This is a great pitfall for ``the next guy'' who is going to use this code.
This design is only pleasing to sociopaths.
One better way is with (horrors) a label. Both ADA and (extended) PL/I
do this, and it seems to work pretty well. The exact forms differ from
language to language, but in C it might take the form of
while( ... )
command_char:
switch( ... )
{
case ..:
... lots of code ...
break command_char;
... lots more code ...
break;
case ..:
...
}
This is now solidly immune to the addition of new levels of control between
the structure to be ``broken'' and the decision to break it.
--
from Mole End Mark Terribile
(scrape .. dig ) hou4b!mat
,.. .,, ,,, ..,***_*.
More information about the Comp.lang.c
mailing list