Ralf Flechsig

Why CodeWarrior couldn't handle unions???

Discussion created by Ralf Flechsig on Feb 7, 2007
Latest reply on Feb 20, 2007 by Daniel Lundin
Hello,
I use C as language:

So i have declared unions, take a look:
****
union Byte{
char c;
unsigned char uc;
};
union DoubleByte{
union Byte by[2];
WORD w;
UWORD uw;
};
****
But if i call sizeof:
union Byte = 2
union DoubleByte = 4

Why did the codewarrior compiler do this? (Double size???)
And why it places the startaddress of ,e.g., by[1] in union DoubleByte at a place 2 bytes away from the startaddress of by[0]?
I have tested other compilers and they did the work! I mean, they don't put a 2-byte distance between two entries of an 1-byte-Array.

Can anyone tell me, if this is an option to configure in the IDE or is this bug something, the other compilers should do also, if they would do correct C.

Thanks

Outcomes