problems/risks due to programming language
Dave Jones
djones at megatest.UUCP
Sat Feb 24 09:15:26 AEST 1990
>From article <2903 at goanna.oz.au>, by ok at goanna.oz.au (Richard O'keefe):
> There's been a lot of discussion about the "switch" statement.
> What people seem to have missed is that there are TWO debatable
> features about C's "break" statement, one of which was NOT
> present in C's grandfather BCPL.
I'll add a third one. Or maybe it's just a bug in the compiler I use.
I've been programing in C full time for about six years
now, so I don't make many mistakes, but I made this one the other day:
enum bar { biff, bam, boom };
proc()
{ enum bar foo;
/* ... */
switch(foo) {
case biff:
do_this();
break;
case bad:
do_that();
break;
boom:
do_the_other();
break;
}
}
(The cases were separated by more lines of code.) The compiler loved
it. Sun's cc allows this if the enumeration is declared globally, but
not if it is declared within a block, if I remember correctly.
Of course, testing exposed the mistake, and a fellow whom I
asked to "look at this and see what I'm missing," looked at it
and saw what I was missing.
More information about the Comp.lang.c
mailing list