Warning

Charles noone at nowhere.com
Thu Feb 23 09:50:46 PST 2006


> NEVER MIX VALUE AND REFERENCE types in a union!

Hmm Ive never heard ( or done ) this, why is that ?


"Georg Wrede" <georg.wrede at nospam.org> wrote in message
news:43FDD956.5020603 at nospam.org...
> 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