An amusing piece of code

Joseph S. D. Yao jsdy at hadron.UUCP
Tue Apr 8 14:54:25 AEST 1986


In article <1370 at ism780c.UUCP> tim at ism780c.UUCP (Tim Smith) writes:
>	switch ( thing ) {
>case A:         A-code; break;
>case B:         B-code; if ( 0 ) {
>case C:         C-code; if ( 0 ) {
>case D:         D-code; }}
>		BCD-common-code; break;
>case E:         E-code;
>	}

Assuming that you can't put BCD-common-code into a function, I
agree with everyone else that you should use [forward-referencing!]
goto's here, and [again] cite Prof. Knuth's _Structured_Programming_
_with_Goto's_.  One major problem is that this code jumps into blocks
[the effect of case C: and case D: ].  This is something that X3J11
warns about.  I thought K&R did, too; but I can't find it.  It is
generally a bad practice, although most compilers seem to allow it
without too much trouble.



More information about the Comp.lang.c mailing list