Think of the union as allowing two variable spaces to overlap. To take a simple case, if you union a two-bye char array with, say, an int, you actually overlap the physical storage. So, suppose you initialise each of the two chars with 0x00, and then you read the int, the int will be 0. Similarly, if you set the two chars as 0xff, when you read the int it will be -1 (assuming an int is 16-bits and is signed in your implementation).
In the example I give above, we stumble upon the matter of endian-ness. Assuming we always speak in terms of ascending address value, some systems store variables hi-byte first, others lo-byte first; big-endian and little-endian respectively. You will have to take a good look at the assembly language compiler output, or just experiment, to determine which way around things are; but I would try big-endian first. On Friday 16 January 2009 21:44:38 ronnym...@aol.com wrote: > Thanks for the Union lead. In my C reference, it is unclear whether the > variables will be unchanged when reinitializing the space from a char to a > long and vice versa. Do the variables keep their same value? In other words > will the long...0xFFEEEEDD, come out as 0xDD,0xEE,0xEE,0xFF if I re > initialize the space as bytes?? Thanks again, > Ron <snip> -- Richard. PGP Key-id: 0x5AB3D350 ------------------------------------------------------------------------------ This SF.net email is sponsored by: SourcForge Community SourceForge wants to tell your story. http://p.sf.net/sfu/sf-spreadtheword _______________________________________________ Sdcc-user mailing list Sdcc-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sdcc-user