Warning
Georg Wrede
georg.wrede at nospam.org
Thu Feb 23 07:48:38 PST 2006
Derek Parnell wrote:
> Sorry, but I forgot something nice. Anonymous structs don't seem to be
> solving any problem that I've come across, but anonymous unions are very
> nice.
>
> struct S
> {
> int type;
> union {
> int i;
> long l;
> short s;
> real r;
> float f;
> Foo foo;
> }
> }
Of course you know, and all regulars here know, but the casual reader
has to be warned here.
NEVER MIX VALUE AND REFERENCE types in a union!
While technically it poses no problem, in real life you'll end up
shooting yourself in the foot -- faster than it takes to say 'Ouch!'
And if you don't, the later maintainer of your code *will* shoot you.
More information about the Digitalmars-d
mailing list