pTAL Reference Manual (H06.08+)
Structures
HP pTAL Reference Manual—523746-006
9-27
Alignment of UNSIGNED(17-31) Fields
Alignment of UNSIGNED(17-31) Fields
In a SHARED8 structure, UNSIGNED(17-31) fields cannot cross a 4-byte address.
Because an UNSIGNED(17-31) field is longer than 16 bits, its base alignment is 4
bytes.
In Example 9-21 on page 9-27, i starts at the beginning of the structure. u, therefore,
begins at an even-byte offset from the beginning of s. Because u is 28 bits, the last 12
bits of u would be allocated in the next word, which would cause u to cross a 4-byte
address.
You must explicitly declare filler to force u to begin at the next 4-byte offset from the
beginning of s.
Reference Alignment With Structure Pointers
When you declare a structure pointer, you can specify a REFALIGNED clause as part
of the declaration. (For the syntax of a structure pointer, see Section 11, Equivalenced
Variables.) You can use a REFALIGNED clause to override the base alignment of an
instance of a structure, even though the field alignment for the structure does not
change. For example, if you specify a REFALIGNED(2) clause on a structure pointer,
pTAL generates conservative code each time you use the pointer to reference fields of
the structure.
A REFALIGNED clause specifies the base alignment of the structures that the
structure pointer will reference. The distinction between FIELDALIGN and
REFALIGNED is required because structures referenced by a structure pointer can be
located anywhere in memory, and might not be well-aligned. A structure might not be
well-aligned if it is located in a dynamic memory area such as a heap, or was read from
a file as part of a larger record.
Example 9-21. SHARED8 Structure With Misaligned UNSIGNED Fields
STRUCT s FIELDALIGN(SHARED8);
BEGIN
INT i;
UNSIGNED(28) u; ! Invalid field
END;
Example 9-22. SHARED8 Structure With Correctly Aligned UNSIGNED Fields
STRUCT s FIELDALIGN(SHARED8);
BEGIN
INT i;
FILLER 2; ! Forces u to begin at a 4-byte address
UNSIGNED(28) u;
BIT_FILLER 4; ! Makes length of s an integral multiple of
END; ! 4 bytes










