Differences in c and c++ anon typedefs

Brendon Costa bcosta@avdat.com.au
Mon Nov 27 01:20:00 GMT 2006


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. In the C++ front end 
TYPE_MAIN_VARIANT returns the type "Blah" where as in the C front end 
this returns an anonymous RECORD_TYPE node.

If i then change the code to look like:

typedef struct
{
    int b1;
    int b2;
} Blah, Another;


And apply the TYPE_MAIN_VARIANT on "Another", C++ returns Blah and C 
again returns the anonymous RECORD_TYPE. In my situation this is causing 
some grief as i need a consistent name for the main varient type across 
translation units. The C++ front end will allow me to do this by the 
fact that it returns "Blah" as the main varient, however the C front end 
does not.

Is there some way in the C front end of obtaining "Blah" from the 
anonymous RECORD_TYPE node?

I was thinking of looking at the first TYPE_NEXT_VARIANT of the 
anonymous RECORD_TYPE node which may give me "Blah", but I am not 
certain it will do so all the time... Does anyone know if this will work 
or if there is a better way?


Thanks,
Brendon.



More information about the Gcc mailing list