Hello, as you know any element of the union starts with same address, and so.. the size of the union should be the size of the biggest element... right?
but here what i have:
Code:
union myunion
{
short mem1;
int mem2;
double mem3;
char str[10];
};
union myunion u1;
now, when i do sizeof(u1) i get 12! but i should get 10, isnt it?
interesting thing is, when i do it like that:
Code:
union myunion
{
short mem1;
int mem2;
double mem3;
char str[12];
};
union myunion u1;
and then perform again sizeof(u1), i get the correct size of 12!
any ideas WHY?
and here is the size of types on my system:
short 2
int 4
double 8
char 1