The final word on GOTO (Don't I wis

Blair P. Houghton bph at buengc.BU.EDU
Sat Oct 7 04:08:41 AEST 1989


In article <867 at crdos1.crd.ge.COM> davidsen at crdos1.UUCP (bill davidsen) writes:
>In article <4447 at buengc.BU.EDU>, bph at buengc.BU.EDU (Blair P. Houghton) writes:
>
>|  I'd go out of my way to fix it so that I could just do
>|  
>|  	switch(format_char) {
>|  	    case 'd': the stuff I put under d; break;
>|  	    case 'o': the stuff I put under o; break;
>|  	    case 'x': the stuff I put under x; break;
>|  	    case 'u': the stuff I put under u; break;
>|  	}
>|  
>|  	the stuff I put under donum;
>
>  This doesn't do the same thing at all. In the original the "donum:"
>code was only executed if a case was matched in the switch. Your example

Quite so.

>executes it everytime. As you mentioned but didn't show you would have
>to define a bunch of flags and stuff to make this work.

Not really:

	switch(ch = format_char) {
		/* Switch body exactly as above */
	}

	switch(ch) {
	    case 'd':
	    case 'o':
	    case 'x':
	    case 'u':
		the stuff I put under donum;
		break;
	    default:
		break;
	}

I only did the extra assignment to give the switch body full use of
the variable format_char.  It may well be unnecessary in our hypothetical
example.

				--Blair
				  "One variable of indeterminate
				   necessity and an improvement
				   in the maintainability of the
				   do-for-all-flags code.
				   How many marks out of ten,
				   Dr. Structmember-Offset?"



More information about the Comp.lang.c mailing list