Explanation, please!
Douglas C. Schmidt
schmidt at bonnie.ics.uci.edu
Thu Aug 25 12:16:14 AEST 1988
The following piece of wonderful obscurity comes from Stroustup's
C++ Programming Language book, page 100:
void send(int *to,int *from, int count) {
int n = (count + 7) / 8;
switch(count % 8) {
case 0: do { *to++ = *from++;
case 7: *to++ = *from++;
case 6: *to++ = *from++;
case 5: *to++ = *from++;
case 4: *to++ = *from++;
case 3: *to++ = *from++;
case 2: *to++ = *from++;
case 1: *to++ = *from++;
} while (--n > 0);
}
}
Now, much to my surprise, this is not only valid C++, it is also valid C!
Could some one please explain to me why this is so? It seems like
the case 7-1 labels are actually nested inside the do {} while loop,
and thus not in the scope of the switch (should a break statement exit
both the switch and the loop, or just one?!?!).
Finally, Stroustrup asks the rhetorical question ``why would anyone
want to write something like this.'' Any guesses?!
thanks,
Doug Schmidt
--
Douglas Schmidt
"If our behavior is strict, we do not need fun." -Zippy th' Pinhead
"If our behavior is struct, we do not need defun." -Anon
More information about the Comp.lang.c
mailing list