Effect of Structure Packing on Alignment

As long as the alignment rules discussed in the previous section, Rules for Alignment of Complex Types, are observed, no alignment errors occur. Structure packing, however, interacts with compiler alignment behavior as follows.

For each member of a structure:

Thus, if the packsize is set to 4, data types having a size of 4, 8, or 16 bytes would be aligned on addresses that are multiples of four. However, there is no guarantee that data types 8 bytes in size (64 bits) would be aligned on addresses that are a multiple of eight. The packsize has no effect on data types outside of a structure.

The following techniques set a packsize, in bytes:

For example, the /Zp1 option sets the packsize to 1, which causes the compiler to use no padding within structures. Consequently, any data type that has an alignment factor larger than 1 may cause an alignment fixup to occur when accessed. To avoid this problem, either turn off structure packing or use the _ _unaligned keyword as described in Alignment Issues on Alpha.