-zalign affects the mapping of structure members. z/OS structure mapping rules use a "shift-to-align" algorithm to minimize compiler inserted pad bytes for the alignment requirement of structure members. This differs from the default Open PL/I structure mapping rules described in the Structure topic, which are compatible with other UNIX and Windows compilers for inter-language compatibility.
-zalign implies:
Structure Layout Example (Open PL/I default)
The following shows structure ST with size 8 bytes; member "C" is at offset 0 (byte alignment) and member "X" is at offset 4 (word alignment), with 3 compiler-inserted pad bytes between.
1
2 dcl 1 ST,
3 2 C CHAR,
4 2 X FIXED BIN(31);
5
NAME CLASS SIZE LOCATION ATTRIBUTES
ST BASED 8 LEVEL 1 STRUCTURE
C MEMBER 1 00000000 LEVEL 2 CHAR(1)
3 00000001 -pad-
X MEMBER 4 00000004 LEVEL 2 FIXED BIN(31,0)
Structure Layout Example (-zalign)
The following shows structure ST with size 5 (8 bytes are allocated in memory); member "C" is at offset 0 (byte alignment) and member "X" is at offset 1 (word alignment). In this example each member is shifted by 3 bytes (OFFSET=3 as shown below) to properly align each member on its required boundary, thus minimizing (and in this case eliminating) compiler-inserted bytes. Effectively, the "shift-to-align" algorithm propagates pad bytes that fill natural alignment gaps between members toward the beginning of the structure. Pad bytes which have been shifted outside the structure (that is, preceding the first member) are known as "hang bytes".
1
2 dcl 1 ST,
3 2 C CHAR,
4 2 X FIXED BIN(31);
5
NAME CLASS SIZE LOCATION ATTRIBUTES
ST BASED 5 LEVEL 1 STRUCTURE OFFSET=3
C MEMBER 1 00000000 LEVEL 2 CHAR(1) UNALIGNED
X MEMBER 4 00000001 LEVEL 2 FIXED BIN(31,0)