The z/OS® XL C compiler aligns structure and union members according to their natural byte boundaries and ends the structure or union on its natural boundary. However, since the alignment of a structure or union is that of the member with the largest alignment requirement, the compiler may add padding to elements whose byte boundaries are smaller than this requirement. You can use the _Packed qualifier to remove padding between members of structures or unions. Packed and nonpacked structures and unions have different storage layouts.
union uu{
short a;
struct {
char x;
char y;
char z;
} b;
};
union uu nonpacked[2];
_Packed union uu packed[2];
┌───── nonpacked[0] ─────────── nonpacked[1] ───┐ │ │ │ │ a │ │ a │ │ │ x │ y │ z │ │ x │ y │ z │ │ ⋘─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘ 0 1 2 3 4 5 6 7 8
┌─── packed[0] ───┬─── packed[1] ───┐ │ │ │ │ a │ │ a │ │ │ x │ y │ z │ x │ y │ z │ ⋘─────┴─────┴─────┴─────┴─────┴─────┘ 0 1 2 3 4 5 6
If you specify the _Packed qualifier on a structure or union that contains a structure or union as a member, the qualifier is not passed on to the nested structure or union.