Unions and Structs
anonymous via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jan 18 09:17:18 PST 2016
On 18.01.2016 18:10, Russel Winder via Digitalmars-d-learn wrote:
> So this is an error?
>
> union flob {
> ulong data;
> struct thingy {
> uint data;
> uint bits;
> }
> thingy burble;
> };
>
> because you cannot have a union field with a name that is also the name
> of a struct field defined within the union.
I don't see the problem. You have to access the thingy's 'data' through
the 'burble' member, so there is no ambiguity, is there?
This would be different, and dmd rejects it accordingly:
----
union flob {
ulong data;
struct {
uint data; /* test.d(4): Error: variable test.flob.data conflicts with
variable test.flob.data at test.d(2) */
uint bits;
}
}
----
More information about the Digitalmars-d-learn
mailing list