This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Scopes in which __label__ can appear


On 19-Jul-2003, Gabriel Dos Reis <gdr@integrable-solutions.net> wrote:
> Mark Mitchell <mark@codesourcery.com> writes:
> | I agree with Zack.
> | 
> | __label__ should have two effects:
> | 
> | #1: It makes the label accessible to a nested function.
> 
> This is  not under dispute.
> 
> However, you may notice that for a nested function, identifiers in the
> enclosing scope are visible, so #1 is actually unnecessary.
> But I'm not saying we should remove it, just noting that it is not
> as essential as it is being stated.

The issue is complicated because labels in C do not have to be
forward-declared.  A "goto" statement acts as an implicit
declaration of a label whose scope is the entire function,
even if the "goto" occurs in a nested block.
When you extend standard C to allow nested functions, you have
to ask what is the scope of a label whose first occurrence is in a
"goto" in a nested function -- is it just the innermost nested function
in which the "goto" occurs, or is it the whole outermost function?

GCC answers that question by saying that the scope is just the
innermost nested function.

Given that decision, allowing labels in the enclosing scope to be visible
in nested functions would mean that the scope of a label could not be
determined when that label is first encountered in a "goto" statement,
but would instead depend on what label definitions follow.

So, making labels in a containing function scope over nested functions
would require either (a) supporting entities whose scope cannot be
determined when they are first encountered, which would be a rather radical
change from the normal forward declaration style for C that supports
one-pass compilation, or (b) abandoning the decision that labels which
occur in nested functions do not scope over the whole containing function,
which would mean that labels with the same name occurring in two
different nested functions in the same containing function would
conflict with each other.  Neither of these is particularly desirable.
So the decision to require the use of __label__ to make labels
in a containing function accessible in nested functions,
though not absolutely essential, is nevertheless fairly strongly
motivated and hence quite understandable.

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]