public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Problem with anonymous structs and unions
@ 2002-11-13  1:38 mramirez
  2002-11-13  9:15 ` Oscar Fuentes
  0 siblings, 1 reply; 4+ messages in thread
From: mramirez @ 2002-11-13  1:38 UTC (permalink / raw)
  To: gcc-help

Hi,

I am having problems to compile the following snippet of code:

struct Vector2
{
    union
    {
        struct
        {
            float x, y;
        };
        struct
        {
            float u, v;
        };
    };
};

int main( int argc, char** argv )
{

    Vector2 vertex;

    vertex.x = 100.0f;
    vertex.y = 50.0f;

    Vector2 texCoord;

    texCoord.u = 0.75f;
    texCoord.v = 0.025f;

    return 0;
}

g++-2.95 complains in the following manner:

mramirez@mtg100:~/anonymous$ g++ -o test test.cxx
test.cxx:11: anonymous class type not used to declare any objects
test.cxx:15: anonymous class type not used to declare any objects

Since this works fine under other compilers ( don't ask which ones ), I am
suspecting that that union-structtuple is violating either the standard or the gcc "way of doing things",
isn't it?
For the case above mentioned there's a simple workaround:

struct Vector2
{
    union
    {
        float x;
        float u;
    };

    union
    {
        float y;
        float v;
    };
};

So I can port most of these expressive vector types, except when
expressivity is further augmentedby providing a union with an array, for instance. I could relay on
returning a pointer to the first memberdeclared, but that's likely to provide interesting bugs when combined with
"exotic" alignments.
Any ideas?

Miguel Ramírez


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-11-14  9:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-13  1:38 Problem with anonymous structs and unions mramirez
2002-11-13  9:15 ` Oscar Fuentes
2002-11-13  9:58   ` Eljay Love-Jensen
2002-11-14  1:00     ` Miguel Ramírez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).