Scopes in which __label__ can appear
Zack Weinberg
zack@codesourcery.com
Sat Jul 19 19:27:00 GMT 2003
Gabriel Dos Reis <gdr@integrable-solutions.net> writes:
> | Does your opinion change if I point out that the documented effect of
> | __label__ has always been to give the label a local scope? It happens
> | only to work in the context of statement expressions, but the
> | documentation doesn't say that.
>
> if it does not work in the context of statement expressions, what
> usefulness would it have? (This is a real question, not a rhetorical
> one).
Abstractly speaking, there are two effects of __label__:
1) It makes the label visible to 'goto' from a nested function.
(This one is not under discussion right now.)
2) It narrows the scope of the label to the block in which the
__label__ declaration appears.
These two effects are clearly documented. Whether or not we should
have this extension in the first place is beyond the scope of this
discussion.
If __label__ did not narrow the scope of the label to the block in
which it appears, it would be useful only for making the label visible
to 'goto' from a nested function. I suspect that this effect is
rarely used, compared to the scope-narrowing effect.
Now, in the present implementation, if __label__ appears at nested
block scope, but the nested block in question is not a statement
expression, effect (2) does not happen. I am convinced that this is
an accident of the implementation, not an intentional behavior. There
is no particular reason (from a language design point of view) why the
scope-narrowing effect should be limited to statement expressions.
Does that answer your question?
zw
More information about the Gcc
mailing list