Language Implementation
7-9
7
Figure 7-2 User-constrained Alignment
Byte 0
8
4
00 7 0 7
7
0 7
b
a
c
d
OSD830
Byte 0
4
00 7 0 7
7
0 7
a
d
XXXX
XXXX
d
b
c
Alignment is 2; Size is 10
Alignment is 1; Size is 8
A user-constrained alignment larger than the natural alignment aligns the
structure on the natural-alignment boundaries. User-constrained
alignment can increase the amount of tail padding relative to natural
alignment but does not increase the padding between members of a
structure. For example, specifying an alignment of
16 for strc1 aligns
the structure as in Figure 7-1.
When a
struct has a member that is also a struct, the alignments of the
member type and of the container need not be the same. For example:
struct NATURAL
{
char c1;
short s;
char c2;
}
struct CONSTRAINED_1
{
char c;
struct NATURAL n;
}