AA,
A union differs from a structure. A union is a common storage for different data types. In your example, you can use it as an integer or double or a character at a time.
BR,
Amr Ali.
AA,
A union differs from a structure. A union is a common storage for different data types. In your example, you can use it as an integer or double or a character at a time.
BR,
Amr Ali.
Hmm...
If the size of this union is 8, there's enough space to hold tha value of "d". Right?
What about "i" than? Where is it held if all the space is occupied by "d" (which is 8 )???
I assume you switched the sizes of mu.d and mu.c: 8 and 1 respectively.
If you do
Code:
if( mu.d == mu.i) { code... }
then the compiler will read the 2 first bytes of mu, interpret them as an integer, read the 8 bytes of mu and interpret them as a double precision floating point number, and then do the comparison. If you're lucky and they are special values (zero?) you might have a chance that they match. But of course this can never be the intended use of an union. You always use a union ONE MEMBER at a time: you have to keep track what's contained at a certain moment and only use it that way.