A good use of a bad feature
KW Heuer
kwh at bentley.UUCP
Fri May 9 14:18:07 AEST 1986
In article <528 at brl-smoke.ARPA> root at icst-cmr ((Root Boy) Jim Cottrell) writes:
[concerning the fall-through case feature]
>You will find much disagreement on that point, I'm afraid. Fall thru is
>more flexible. You can always break, but often cases are related so that
>a particular case requires a superset of another case. It is to DMR's
>credit that he realized this feature. I sure wouldn't have thought of it.
An alternate implementation would have been for cases to be distinct by
default, but "continue" at the bottom of a case would cause a fall-thru.
(In this model, "break" would be meaningless inside a switch and "continue"
would be meaningful, instead of the opposite.) Given that most use of the
switch statement *does* have distinct cases, and the exceptions are often
explicitly labeled /* no break */, I think this would've been better.
(I would *almost* accept a model with automatic break and no keyword for
fall-thru, and suffer the occasional goto.)
One special instance is where the superset is actually an equivalence, i.e.
two or more labels on the same code:
case ' ':
case '\t':
case '\n':
white();
break;
This would be ugly with the auto-break model, but the solution is to allow
case ' ','\t','\n':
white();
which I think looks neater anyway.
(Btw, I find
case '0':
...
case '9':
digit();
annoyingly verbose in the current model, and often use "if" rather than
"switch" because of it.)
Karl W. Z. Heuer (ihnp4!bentley!kwh), The Walking Lint
More information about the Comp.lang.c
mailing list