Scopes in which __label__ can appear
Gabriel Dos Reis
gdr@integrable-solutions.net
Sat Jul 19 18:53:00 GMT 2003
"Zack Weinberg" <zack@codesourcery.com> writes:
[...]
| should either be ill-formed on the grounds that __label__ cannot
| appear at nested block scope other than a statement expression or
| nested function, or it should be well-formed and equivalent to
|
| int s(int i)
| {
| if (i > 1) return 0;
| if (i == 1) return 1;
| if (i < 0) return 2;
| /* if (i == 0) */ return 3;
| }
|
| but what the present compiler does is reject it on the grounds that l1
| has been defined twice. In other words, the effect of __label__ at
| nested block scope (other than a statement expression or nested
| function) is as if the __label__ appeared at function scope. I think
| this violates least surprise and should be changed.
On the contrary, I think is consistent with the scope of label as
defined by both C and C++ standards.
Remember labels have function-scope. Suddenly changing labels
(explicitly declared -- GNU extension I concede) to have a
local-scope will violates the "least surprise" principle.
C99:
[#3] A label name is the only kind of identifier that has
function scope. It can be used (in a goto statement)
anywhere in the function in which it appears, and is
declared implicitly by its syntactic appearance (followed by
a : and a statement).
C++, 3.3.4/1:
Labels (6.1) have function scope and may be used anywhere in the
function in which they are declared. Only labels have function scope.
I will reject the second example on the ground that it provides two
definitions for the same label in the same (function) scope.
-- Gaby
More information about the Gcc
mailing list