Unchecked Switch Statement
Paul Dietz
dietz%slb-doll.csnet at CSNET-RELAY.ARPA
Wed Mar 12 08:59:25 AEST 1986
This issue has probably been discussed before, but here goes...
There seems to be an philosophical difference in C between array
accesses and switch statements. In array accesses the compiler is free
to generate code that does undefined things if the index is out of
bounds. In contrast, switch statements must fall through if there is
no "default:" label and no "case" matches the switch expression.
A more consistent definition would have the compiler generate
code that checks for an out-of-bounds switch expression only when
a default label is present. The default label could be placed last in
the switch statement to get the same behavior as current default-less
switches.
More information about the Comp.lang.c
mailing list