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: Differences in c and c++ anon typedefs


Brendon Costa <bcosta@avdat.com.au> writes:

| Hi all,
| 
| I have just come across a small difference in the way the C an C++
| front ends handle anonymous struct types which is causing me some
| grief. In particular the following code:
| 
| typedef struct
| {
|     int b1;
|     int b2;
| } Blah;
| 
| void Function(Blah* b) {}
| 
| When i get the Blah type in the function above (After removing the
| pointer) i then use TYPE_MAIN_VARIANT on it and do some special
| processing on the resulting main varient type.

C++ defines a notion of "class name for linkage purpose" -- that is a
notion used to define the One Definition Rule. 
In general the TYPE_NAME of TYPE_MAIN_VARIANT is the class name for
linkage purpose.  
The behaviour you reported on implements the rule 7.1.3/5:

   If the typedef declaration defines an unnamed class (or enum), the
   first typedef-name declared by the declaration
   to be that class type (or enum type) is used to denote the class type
   (or enum type) for linkage purposes only (3.5).

-- Gaby


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