Warning

James Dunne james.jdunne at gmail.com
Thu Feb 23 10:47:30 PST 2006


Georg Wrede wrote:
> 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.

Oh that's nothing - this one time, at home, I serialized pointers to 
disk! =P  And this other time, at work, I wrote a Delphi program to 
serialize a record right from memory out to the disk!  (It wasn't 
packed, and no pointers)

-- 
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/MU/S d-pu s:+ a-->? C++++$ UL+++ P--- L+++ !E W-- N++ o? K? w--- O 
M--@ V? PS PE Y+ PGP- t+ 5 X+ !R tv-->!tv b- DI++(+) D++ G e++>e 
h>--->++ r+++ y+++
------END GEEK CODE BLOCK------

James Dunne



More information about the Digitalmars-d mailing list