pTAL Conversion Guide

Structures
pTAL Conversion Guide527302-002
11- 3
Pictorial Overview of pTAL Structure Alignment
A structure is well-aligned if the address of the base of the structure in memory is a
multiple of its base alignment. Otherwise, the structure is misaligned. If a structure
is misaligned, some or all of its fields will also be misaligned.
pTAL ensures that definition structures and referral structures are well-aligned;
however, if you declare a structure pointer and assign the address of a structure to
it or use a reference parameter to address structure data, the compiler cannot
ensure that the structure is well-aligned; therefore, when you declare a structure
pointer, you can specify what assumptions you want pTAL to make when it
generates code to access your data. You can specify a REFALIGNED clause,
discussed later in this section.
Structures Aligned at Odd-Byte Boundaries
If you attempt to access data at an odd-byte address, the results are undefined,
whether the data is a simple variable or a field of a structure. Your program might
or might not trap.
The following example illustrate how the data layout of your structure is affected by
structure alignment. Only SHARED8 structures are shown because SHARED2
structures are by definition not well-aligned—pTAL always generates conservative
code for references to fields of a SHARED2 structure that are more than 16 bits.
Figure 11-1
on page 11-4 shows a structure, s1, that specifies
FIELDALIGN(SHARED8). Because the widest field in the structure, f, is a FIXED field,
the base alignment of s1 is 8. To be well-aligned, s1 must be allocated at a memory
address that is an integral multiple of eight. Filler is added as follows:
Before the INT(32), i32, so that i32 begins at an offset that is a multiple of four
relative to the beginning of the structure.
Before the FIXED field f so that f begins at an offset that is a multiple of eight
relative to the beginning of the structure.
At the end of the structure so that the total length of the structure is an integral
multiple of the widest field in the structure, f, which is data type FIXED.
Table 11-1. Structure Base Alignment
Width of Widest
Field in Structure FIELDALIGN (SHARED2) FIELDALIGN (SHARED8)
1 1 or 2* 1 or 2*
22 2
42 4
82 8
* Definition (inline) substructures have a base alignment of one. All other structures—definition structures,
referral structures, and referral substructures—have a base alignment of two.