Depends where the fallthrough occurs, no?
Furthermore, why on earth would I care?
I do actually have at least one case where a fallthrough is used to
allow two cases in a switch to share code with several other cases.
(Note that this can be handled by a nested if.)
switch (x) {
case 0:
printf("roly poly ");
/* FALLTHROUGH */
case 1: case 2:
printf("fish heads\n");
break;
default:
printf("sorry, can't think of any other songs.\n");
break;
}
===
if (x == 0 || x == 1 || x == 2) {
if (x == 0) {
printf("roly poly ");
}
printf("fish heads\n");
} else {
printf("sorry, can't think of any other songs.\n");
}
But who CARES? I'm not here to comply with an arbitrary set of abstract
"rules of structured programming". I'm here to write clear, legible, C,
conforming to the conventions and idioms of that language.
(Aside to Seebs: I was going to include /* FALLTHROUGH */ comments
but realized I wasn't sure where they should go. ? )
There isn't a completely general convention. Usually, they go precisely
where the "break;" would have gone if there were no fallthrough, except
that sometimes they're put on the case labels rather than at the end of
the material under the case.
This criticism is particularly illucid, simply because the original complaint
given was that I should not have called an error routine for those cases.
But in fact, I did exactly that -- I wrote code to call an error routine
if those ever occur.
It feels like you're dumber than I could possibly imagine. The key
distinction, I think, being that my criticisms of Schildt are actually
correct, whereas your criticisms of my code so far show an astounding
lack of comprehension of basic C.
Up to a point, yes. There is a reason to have high-level documentation,
though, which is that no amount of "readable" makes up for the reader
not understanding the basic goal of the program.
Colorless green ideas sleep furiously!
But that's not client code.
Come on, really. What function had the disputed MSG_ACK and MSG_NAK?
"pseudo_server_response()"
I do not think it is reasonable for anyone to suspect that this is
"client code".
As to whether I should put in cases for an "invalid" condition: One of the
reasons pseudo exists is that other tools we'd used were not robust enough;
they could crash or otherwise fail. As such, pseudo is full of tests for
conditions that are obviously impossible *if the rest of the code is free
of bugs*. What this means is that even when there have been bugs (and there
have), the program has continued to work, with a grand total of one reported
failure in the field.
At one point during internal testing, I had a bug in the server which caused
it to crash under fairly common circumstances. It went unnoticed for a
week or two because the recovery code kept things running smoothly anyway.
-s