This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Unnamed unions
- To: gcc at gcc dot gnu dot org
- Subject: Unnamed unions
- From: "Timothy J. Wood" <tjw at omnigroup dot com>
- Date: Fri, 16 Feb 2001 15:12:04 -0800
I end up porting a lot of code that is built with VC++ and/or
Metrowerks to Mac OS X using gcc. Apparently both of these compilers
support the following:
struct {
union {
int a, b;
};
} x;
int main()
{
x.a = 1;
return 0;
}
That is, any union that has no name is treated like all the elements
are in the name space of the enclosing struct. Presumably if you have
two unions like this in the same struct, they would have namespace
collisions even though they don't occupy the same space (I've only seen
this in one project, though).
I looked through the gcc sources and docs and didn't find any
indication that there is a flag to allow this in gcc. Did I miss it, or
is this just forbidden?
This isn't that hard to work around ... it's just tedious and annoying
(both to me and my customer when I hand them back a patch that has 1000s
of lines of changes like this).
Would a patch for this be accepted (-funnamed-
unions/-fno-unnamed-unions with the latter being the default)? Not sure
if I'd be able to do it, but it might be pretty easy to hook in ....
-tim