problems/risks due to programming language
William Thomas Wolfe, 2847
billwolf%hazel.cs.clemson.edu at hubcap.clemson.edu
Sun Feb 25 11:42:57 AEST 1990
>From peter at ficc.uu.net (Peter da Silva):
> On the other hand, the people (inlcuding Bill) arguing that switch...break
> is an unalloyed disaster are also all wet. The C SWITCH is not a Pascal
> CASE, it's a computed goto: [Fallthrough example]
Which, amazingly enough, I explicitly noted in my original article:
[...] In C, the case statement *requires* the
use of a restricted GOTO in order to accomplish "normal" processing;
at the end of the section of code processing a given case, one must
use a restricted GOTO in order to prevent C from sending the flow of
control straight into the section of code which was intended to process
the NEXT case. In other words, C requires the programmer to use a
dangerous construct on a routine basis.
Many (including Peter) have re-observed that this is the way C's switch
currently operates, but to date nobody has provided any justification for
having it continue to operate that way. Apparently the thinking is that
if the current definition is repeated often enough, it will be accepted
regardless of how completely bizarre it is.
Given the fact that switch..break results in the generation of many
unnecessary lines of "break" code, that it requires its users to get
into the habit of using a restricted GOTO to accomplish "normal"
processing (the expensive nature of this habit being dramatically
demonstrated by the recent nationwide AT&T crash), and that there
is a widely used (and considerably safer) alternative, it would seem
that C would be considerably better off if it were to either redefine
or replace its switch construct with a case statement.
Bill Wolfe, wtwolfe at hubcap.clemson.edu
P.S. Pending this change, feel free to use Ada instead... :^)
More information about the Comp.lang.c
mailing list