[Icc-avr] Packing of variables in union

John Baraclough j_baraclough at zetnet.co.uk
Sat May 26 10:33:48 PDT 2007


Perhaps I didn't explain myself properly. What is bad programming 
practice is writing one type of variable into a union and then 
reading back a different type. A union is very useful, but can be 
dangerous. Although it may produce the desired result in any compiler 
at any point in time, reading back a different type from that 
written, must not be considered to be portable.

All the best for now,
John

At 23:29 25/05/2007, you wrote:
>Hi Albert,
>
>>Hmmm, I've been pondering about this for a day (not fultime!), and must say:
>>if it really is bad programming, why does it exist? union that is.
>
>
>Hmmmm... The idea is probably to save some memory by physically overlapping
>variables that are never used at the same time. In order to claim the code
>as portable, the "reader" must know which union member (type/variable) the
>"writer" has written and access the variable in the correct "machine
>dependent" way...
>
>Regards
>Johan Bodin
>
>
>
>_______________________________________________
>Icc-avr mailing list
>Icc-avr at imagecraft.com
>http://dragonsgate.net/mailman/listinfo/icc-avr
>




More information about the Icc-avr mailing list