pTAL Conversion Guide

Structures
pTAL Conversion Guide527302-002
11-22
Using Field Alignment
Using PLATFORM Field Alignment
If you specify FIELDALIGN(PLATFORM), the native compiler allocates the structure
and the fields of the structure according to a set of rules that are consistent across all
languages on the same platform (according to the rules used by the HP Native C
compiler for PLATFORM layouts).
pTAL allocates PLATFORM structures as follows:
Each field begins at an address that is an integral multiple of the length of the field.
That is, pTAL allocates one-byte, two-byte, four-byte, and eight-byte fields at
addresses that are integral multiples of one, two, four, and eight, respectively.
UNSIGNED fields are not necessarily aligned to byte boundaries. They can share
one-byte, two-byte, and four-byte containers with other items. An UNSIGNED field,
however, cannot span an address that is an integral multiple of four. If an
UNSIGNED item would span a four-byte address boundary, the compiler allocates
the UNSIGNED field beginning at the next four-byte boundary.
The alignment of a structure or substructure is the alignment of its widest field,
unless the structure or substructure contains an UNSIGNED field, in which case,
the alignment of the structure or substructure is at least four.
The compiler adds bytes, as needed, to the end of a PLATFORM structure or
substructure such that the length of the structure or substructure is an integral
multiple of its widest field.
Example 11-6. Alignment of UNSIGNED(17-31) Fields
Incorrect:
STRUCT s FIELDALIGN(SHARED8);
BEGIN
INT i;
UNSIGNED(28) u; ! This field is invalid
END;
Correct:
STRUCT s FIELDALIGN(SHARED8);
BEGIN
INT i;
FILLER 2; ! Force u to begin at a 4-byte address
UNSIGNED(28) u; ! u begins at a 4-byte address
BIT_FILLER 4; ! Pad to make the length of s
END; ! an integral multiple of 4 bytes