Why not allow "default" as a label?

Dave Sherman dave at utcsrgv.UUCP
Thu Aug 25 01:31:18 AEST 1983

It would be nice if I could say "goto default;" within a switch
statement. I realize "default:" isn't a label, but is there any
reason why it shouldn't be?

Here's the application (part of a routine looking for a yes or no answer):

	. . .
	case 'y':
	case 'n':
	case 'm':
		if(strncmp(p+1, "aybe", 4) printf("Very funny. ");
============>	goto deflt;		<====================================
	case 'o':
		if(*(p+1) == 'k')
		/* fall through */
		printf("Please answer yes or no.\n");
		goto loop;

Obviously, I would like to avoid the use of deflt.
(This is on vanilla v7 UNIX on an 11/23, but the 4.1bsd compiler also
rejects "default" as a label.)

Is the problem related to the fact that there can be multiple defaults
within a routine?

I know I can solve the problem by putting the printf outside of the
switch, in this case. That's not the point. I've run into the problem
in other places too.

Dave Sherman
The Law Society of Upper Canada

More information about the Comp.lang.c mailing list