pTAL Reference Manual (H06.08+)

Structures
HP pTAL Reference Manual523746-006
9-24
Alignment of Fields
If the data type of a field in a SHARED8 structure is an address type, the type must
be EXTADDR, SGBADDR, or SGWADDR, as shown in the following example:
STRUCT s FIELDALIGN(SHARED8);
BEGIN
EXTADDR x; ! OK: EXTADDR field
INT.EXT i; ! OK: EXTADDR pointer
INT.SG j; ! OK: SGWADDR pointer
STRING.s; ! ERROR: BADDR pointer is not valid
END;
Topics:
Alignment of Fields on page 9-24
Optimizing Structure Layouts on page 9-24
Structure Length on page 9-26
Alignment of UNSIGNED(17-31) Fields on page 9-27
Alignment of Fields
If a field in a SHARED8 structure is not well-aligned, you must explicitly declare filler to
force the field to be well-aligned.
The first filler item (FILLER 2) forces b to begin at a 4-byte address. The second filler
item (FILLER 5) forces d to begin at an 8-byte address. The third filler item
(BIT_FILLER 11) forces h to begin at a 4-byte address.
Optimizing Structure Layouts
You do not need to declare filler items in a SHARED2 structure to align its fields. If filler
is neededfor example to align bit fields, string fields, or fields that follow bit fields and
string fieldsthe compiler inserts the needed filler.
Example 9-14. Filler Forcing Alignment in a SHARED8 Structure
STRUCT s FIELDALIGN(SHARED8);
BEGIN
INT a; ! 0 a uses 2 bytes
FILLER 2; ! 2 Force b to a 4-byte offset
INT(32) b; ! 4 b uses 4 bytes
STRING c [0:2]; ! 8 c uses 3 bytes
FILLER 5; ! 11 Force d to an 8-byte offset
FIXED d; ! 16 d uses 8 bytes
INT(32) e[0:1]; ! 24 e uses 8 bytes
INT f; ! 32 f uses 2 bytes
UNSIGNED(5) g; ! 34 g uses 5 bits
BIT_FILLER 11; ! Force h to a 4-byte offset
UNSIGNED(17) h; ! 36 h uses 2 bytes plus 1 bit
UNSIGNED(15) i; ! 38 i uses 15 bits
END; ! Total structure length: 40 bytes