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

From: Greg Jaxon <Greg.Jaxon@synopsys.com>
Date: Mon May 17 2010 - 09:21:51 PDT
David,
     Thanks for the review of this issue in SV's ancestral languages.  I think you've demonstrated
that the LRM cannot rely on the connotations of the struct keyword to invoke a well-known definition.
The arrival (in SV) of struct, class, and enum as part of a OOP revolution clearly suggested the C++ conventions
to some implementers (including me), while others saw things differently.

     The question is whether the P1800 committee ever made this choice explicitly, or if any of the original
Accellera documents possibly referenced C or C++ by name to describe which definition was intended.
The absence of the word "scope" in describing structs does not convince me that P1800 actually made a
choice.  Instead it suggests that the committee were not aware that they had to choose.   Had they been,
I'm sure the desire for clarity would have led them to either affirm or explicitly deny that structs are scopes.

Greg 

David Jones wrote:
On Fri, May 14, 2010 at 2:57 PM, Steven Sharp <sharp@cadence.com> wrote:

  
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.
    

Oh, what fun we have with languages.

The very first C compilers indeed put all struct members in a global
namespace. Such compilers predated even "K&R" C, not to mention ANSI
C. However, if you look at old C sources, and in particular, the Unix
sources (look at some FreeBSD kernel source for example) you can see a
style where each struct member was prefixed to make its name globally
unique. A good example is the "struct stat" found in any POSIX system,
whose members are prefixed with "st_".

Moving on to ANSI C, each struct declaration had its own member
namespace, so you can indeed use the same names in different structs
without collision. However, as far as I can tell from the grammar in
my second edition K&R book, the only thing you can put in a struct is
a member declaration.

C++ is a different beast. Structs and classes in C++ are equivalent,
the only difference being the initial member access (public for
structs, private for classes). Both can contain pretty much any kind
of declaration, and therefore indeed are scopes in their own right.

Section 2.3 of K&R 2nd ed. states that "names in different
enumerations must be distinct".  Section A8.4 further clarifies that
this applies within a scope. Scopes are created inside functions.

And the entire C language grammar takes up only five pages. Those were
the days...
  

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean. Received on Mon May 17 09:22:11 2010

This archive was generated by hypermail 2.1.8 : Mon May 17 2010 - 09:23:53 PDT