VivekGupta22
asked on
Is there any padding possible within a unon
Is there any padding possible within a union like there iare padding fields within a structure.
If you are asking if byte alignment still applies in a union, then the answer is yes
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi VivekGupta22,
> Is there any padding possible within a union
Yes, you can add a "dummy" array:
union my_union {
int real_data_a;
long double real_data_b;
char dummy_padding[16];
};
This will make sure that the union is padded to 16 bytes, regardless of how long double is implemented on your machine (i.e., 80 bit on Intel, 128 on SPARC).
Cheers,
Stefan
> Is there any padding possible within a union
Yes, you can add a "dummy" array:
union my_union {
int real_data_a;
long double real_data_b;
char dummy_padding[16];
};
This will make sure that the union is padded to 16 bytes, regardless of how long double is implemented on your machine (i.e., 80 bit on Intel, 128 on SPARC).
Cheers,
Stefan