pTAL Reference Manual (G06.24+, H06.09+, J06.03+)

Example 73 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
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 Chapter 11 (page 177).) 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.
The alignment of a structure pointer is the alignment specified in a REFALIGNED clause if present,
or if not present, by the field alignment of the structure it references.
The REFALIGNED compiler directive does not affect the reference alignment of structure pointers.
It is used only for pointers to nonstructure data.
You can specify the REFALIGNED clause on any pointer field. In Example 74 (page 134), field d
is a 32-bit pointer in pTAL and is valid only if the field alignment of structure s is AUTO or
PLATFORM.
Example 74 REFALIGNED Clause With Structure Pointers
STRUCT s;
BEGIN
INT .d REFALIGNED(2); ! Standard pointer with REFALIGNED
! clause
INT. EXT e REFALIGNED(8); ! An extended pointer
END;
The same syntax and semantics of fields and pointer fields declared with a REFALIGNED clause
is the same as that of variables and pointers declared with a REFALIGNED clause, respectively.
Topics:
REFALIGNED Clause (page 134)
Default Reference Alignment (page 135)
REFALIGNED(2) (page 135)
REFALIGNED(8) (page 136)
Code Generation for Structure References (page 137)
REFALIGNED Clause
In a SHARED2 or SHARED8 structure, you can include only pointers whose address type is
SGBADDR, SGWADDR, EXTADDR, EXT32ADDR, EXT64ADDR, PROC32ADDR, or PROC64ADDR.
Pointers whose address type is any other type are 16 bits in TAL, but 32 bits in pTAL.
134 Structures