pTAL Conversion Guide

Structures
pTAL Conversion Guide527302-002
11-25
Optimizing Structure Layouts
The alignment for the structures in Example 11-7 on page 11-25 is:
Optimizing Structure Layouts
You do not need to declare filler items in a SHARED2 structure to align its fields. If filler
is needed—for example to align bit fields, string fields, or fields that follow bit fields and
string fields—the compilers insert the needed filler.
Structures that specify SHARED8 field alignment require you to explicitly declare filler
items to force fields to be well-aligned, as previously explained.
You might be able to reduce the size of a structure if you can arrange its fields to
minimize the number of filler items required.
Structure Alignment
S1 2 bytes
S2 4 bytes
S3 8 bytes
S4 4 bytes
Example 11-7. Arrays of Structures and Substructures
STRUCT s1[0:9] FIELDALIGN(SHARED2); ! s1 is SHARED2
BEGIN ! Alignment is 2
INT i;
FILLER 2;
INT(32) j;
END;
STRUCT s2[0:9] FIELDALIGN(SHARED8); ! s2 is SHARED8
BEGIN ! Alignment is 4
INT i;
FILLER 2;
INT(32) j;
END;
STRUCT s3[0:9] FIELDALIGN(SHARED8); ! s3 is SHARED8
BEGIN ! Alignment is 8
STRUCT s4[0:4]; ! s4 is SHARED8
BEGIN ! Alignment is 4
INT i;
FILLER 2;
INT(32) j;
END;
REAL(64) k;
END;