Morris Keesan keesan at bbncca.ARPA
Thu Jun 21 00:30:52 AEST 1984

>   What does
>        switch(i) {
>   	    ...
>   	    switch(j) {
>   	        ...
>   	        default: ...
>   	    }
>       }
>       do if there is no case corresponding to i?
>   	    .
>   	    .
>   	    .
>   Or I could even add a 'goto default'.........
>   (Note: my C Ref Man doesn't say that default is a reserved word,
>   so using default as an ordinary label is perfectly legal)
>   	    Jack Jansen, {philabs!decvax}!mcvax!vu44!jack

    Well, first off, you have a defective "C Ref Man", because the C Reference
Manual in K&R clearly lists "default" as a reserved word (section 2.3, Keywords,
page 180 of K&R).
    Secondly, what happens is clearly defined (section 9.7, Switch Statement):

	Any statement within the statement may be labeled with one or more
	case prefixes . . .

	There may also be at most one statement prefix of the form

	If no case matches and if there is no default then none of the
	statements in the switch is executed.

The "default" in the example above is not a prefix of a "statement within the
statement", but a prefix of a statement within a statement within the statement.
The default will never be considered unless the switch(j) statement is being
executed.  The answer to the question is that the above fragment evaluates i,
compares its value to any case constants (assumed to be in the ...), and then
does nothing else.
					Morris M. Keesan
					keesan @ BBN-UNIX.ARPA

More information about the Comp.lang.c mailing list