Topic: Are anonymous structs in unions standard yet?


Author: "Vis Mike" <visionary25@hotmail.com>
Date: Fri, 10 Aug 2001 09:39:24 GMT
Raw View
Well, now knowing that "-ansi" by itself doesn't do much, the answer is very
clear:

$ /usr/bin/gcc.exe -v
Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/2.95.3-5/specs
gcc version 2.95.3-5 (cygwin special)

$ gcc -ansi -pedantic Material.cpp
Material.h:46: warning: ISO C++ prohibits anonymous structs

Mike

"Martin von Loewis" <loewis@informatik.hu-berlin.de> wrote in message
news:j4d765whsw.fsf@informatik.hu-berlin.de...
> "Vis Mike" <visionary25@hotmail.com> writes:
>
> > I recently encapsulated an OpenGL color value, and realized it may not
be
> > fully portable.  Are anonymous structs such as the one below legal in
ANSI
> > C++?  I compiled the code with 'gcc -ansi' and it doesn't complain.
>
> What version of g++ did you use? It fails to compile for me:
>
> a.c:7: syntax error before `*'
> a.c: In method `Color::Color(float, float, float, float)':
> a.c:4: class `Color' does not have any field named `_redbits'
> ...
> etc
>
> Regards,
> Martin
>
> ---
> [ comp.std.c++ is moderated.  To submit articles, try just posting with ]
> [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
> [              --- Please see the FAQ before posting. ---               ]
> [ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
>
>

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: "Vis Mike" <visionary25@hotmail.com>
Date: Tue, 7 Aug 2001 16:09:55 GMT
Raw View
I recently encapsulated an OpenGL color value, and realized it may not be
fully portable.  Are anonymous structs such as the one below legal in ANSI
C++?  I compiled the code with 'gcc -ansi' and it doesn't complain.

Mike

class Color {
  public:
    Color( float red, float green, float blue, float alpha )
      : _redbits( red ), _greenbits( green ), _bluebits( blue ),
alphabits( alpha ) { }

    GLfloat *glcolor() { return _colorv; }
    static Color white, black, red, blue, green, yellow, magenta, cyan;

  private:
    union {
        struct {
            GLfloat _redbits;
            GLfloat _greenbits;
            GLfloat _bluebits;
            GLfloat _alphabits;
        };
        GLfloat _colorv[4];
    };
};

Color Color::white( 1.0, 1.0, 1.0, 1.0 );
[...]


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: Ron Natalie <ron@sensor.com>
Date: Tue, 7 Aug 2001 21:23:51 GMT
Raw View

Vis Mike wrote:
>
> I recently encapsulated an OpenGL color value, and realized it may not be
> fully portable.  Are anonymous structs such as the one below legal in ANSI
> C++?  I compiled the code with 'gcc -ansi' and it doesn't complain.
>
There are no such things as anonymous structs, in unions or elsewhere.
The code is invalid.  G++ is defective.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: Martin von Loewis <loewis@informatik.hu-berlin.de>
Date: Thu, 9 Aug 2001 18:26:42 GMT
Raw View
"Vis Mike" <visionary25@hotmail.com> writes:

> I recently encapsulated an OpenGL color value, and realized it may not be
> fully portable.  Are anonymous structs such as the one below legal in ANSI
> C++?  I compiled the code with 'gcc -ansi' and it doesn't complain.

What version of g++ did you use? It fails to compile for me:

a.c:7: syntax error before `*'
a.c: In method `Color::Color(float, float, float, float)':
a.c:4: class `Color' does not have any field named `_redbits'
...
etc

Regards,
Martin

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]