pTAL Conversion Guide

Structures
pTAL Conversion Guide527302-002
11-30
Reference Alignment With Structure Pointers
Reference Alignment With Structure Pointers
When you declare a structure pointer, you can specify a REFALIGNED clause as part
of the declaration. (See Section 10, “Pointers,” for the syntax of a structure pointer.)
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.
Topics:
Default Reference Alignment on page 11-30
REFALIGNED(2) on page 11-31
REFALIGNED(8) on page 11-32
Default Reference Alignment
If you do not specify a REFALIGNED clause in a structure pointer declaration, the
reference alignment for the pointer is the alignment of the structure that the pointer
references in its declaration.
Example 11-13. Default Reference Alignment (page 1 of 2)
STRUCT s1 FIELDALIGN(SHARED2);
BEGIN
INT i;
INT(32) j;
END;
STRUCT s2 FIELDALIGN(SHARED8);
BEGIN
INT i;
FILLER 2;
INT(32) j;
END;