[net.lang.c] Why not allow "default" as a label?

dave@utcsrgv.UUCP (Dave Sherman) (08/24/83)

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):

     loop:
	. . .
	switch(*p)
	{
	case 'y':
		return(1);
	case 'n':
		return(0);
	case 'm':
		if(strncmp(p+1, "aybe", 4) printf("Very funny. ");
============>	goto deflt;		<====================================
	case 'o':
		if(*(p+1) == 'k')
			return(1);
		/* fall through */
	default:
	deflt:
		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
Toronto
-- 
 {allegra,cornell,floyd,ihnp4,linus,utzoo,uw-beaver,watmath}!utcsrgv!lsuc!dave