Topic: Anonymous Unions
Author: hf@telematik.informatik.uni-karlsruhe.de (Harald Fuchs)
Date: 26 Nov 92 11:48:47 Raw View
One of the C++ compilers out there disagrees with me with respect to
anonymous unions.
I tried to do the following:
struct Foo {
union {
int bar;
};
int baz;
Foo (int a, int b): bar (a), baz (b) {}
};
The compiler rejected the member initialization for "bar".
It did accept assignment:
Foo::Foo (int a, int b), baz (b) {
bar = a;
}
But of course this won't work for const or reference members.
The ARM says on page 182 something like "The members of an anonymous
union are used directly in the enclosing scope without the usual
member access syntax". So I think the example should be legal.
Should I file a bug report to the compiler vendor?
--
Harald Fuchs <hf@telematik.informatik.uni-karlsruhe.de>
Author: bs@alice.att.com (Bjarne Stroustrup)
Date: 29 Nov 92 15:04:53 GMT Raw View
hf@telematik.informatik.uni-karlsruhe.de (Harald Fuchs @ Karlsruhe University, Germany) writes
> I tried to do the following:
>
> struct Foo {
> union {
> int bar;
> };
> int baz;
> Foo (int a, int b): bar (a), baz (b) {}
> };
>
> The compiler rejected the member initialization for "bar".
> The ARM says ... So I think the example should be legal.
>
> Should I file a bug report to the compiler vendor?
Yes.