Re: [sv-bc] Query related with the visibility of enum member.

From: John Michael Williams <john@svtii.com>
Date: Mon May 17 2010 - 14:28:00 PDT

Hi Steven.

In C, any code enclosed in braces is in a new local scope. The
special case is that of a variable declared in a function body.

Braces indicate boundaries of a stack frame.

Expressions within braces can reference variables outside the braces,
just as in a function; but, a variable in braces can not be
referenced by its bare name outside the braces.

For example, in the body of a function,

MyFun ( ... )
{
  ...
  int A;
   { int A;
     ...
     A = B*C;
   }

return (...);
}

There is no name conflict between the two declarations of A,
and the assignment of B*C is to the inner A.

A is an automatic variable (both of them) unless declared static.

All this is carried over to C++, I am sure.

On 05/14/2010 11:57 AM, Steven Sharp wrote:
> There would have been a certain elegance to regarding a struct as a
> scope, and struct member selects as simply another form of hierarchical
> reference into that struct scope. However, I don't believe that the LRM
> has done that. Structs are not defined to be scopes in the LRM.
>
> I don't think the LRM actually says that the same member name can be
> re-used for a different struct type. We all assume it automatically, from
> our experience with other languages. Even after we accept this as true,
> it does not mean that it comes from a general rule about scopes as applied
> to structs. Since structs are not defined to be scopes, it would have to
> come from a more specific (unwritten) rule about structs.
>
> Since the feature and most of its syntax and semantics came from C, we
> can also compare this aspect to C. I did some testing with gcc to check
> that my understanding of this was correct. In C, different structs can have
> members with the same name. However, a struct is not a scope. If this
> same kind of anonymous enum declaration is done in C, the enum constants
> are visible outside the struct. If a second struct is declared with the
> same anonymous enum names inside it, this produces an error for redeclaring
> the same name.
>
>
> Steven Sharp | Architect | Cadence
>
> P: 508.459.1436 M: 774.535.4149 www.cadence.com
>
>
>

-- 
      John Michael Williams
      Senior Adjunct Faculty
Silicon Valley Technical Institute
-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Mon May 17 14:25:44 2010

This archive was generated by hypermail 2.1.8 : Mon May 17 2010 - 14:28:15 PDT