when you declare
Code C - [expand] |
1
2
3
4
5
| union Test{
char ch;
int value;
long address;
}Union_Test; |
the union size will be the one of the longest variable type,
in this case you have an 8bit char, 16bit int (probably) and 32bit long.
so the value will be 32bit.
Depending on the value you assign the value to , different bits will be written ,
when you assign a value to char ch then only the red bits will be written
when you assign a value to int value then only the blue bits will be written
when you assign a value to long address then all the green bits will be written,
all the other bits will remain unchanged and the (32 bit) value will be wrong if you write a char value over the long value (because the higher bits will keep the old value).
000000000000000000000000
00000000
0000000000000000
0000000000000000
00000000000000000000000000000000
Alex