Language Implementation
7-23
7
The compiler aligns a struct type at the opening brace that brackets the
struct declaration list, according to the following rules:
Rule 1 If the
struct type has a tag and the tag identifier has appeared
in an alignment pragma, the alignment is specified by the most
recent alignment pragma for the tag identifier.
Rule 2 If the
struct type has no tag and the struct declaration list
is nested within another
struct declaration list, the alignment
is the same as that of the immediately enclosing
struct type.
Rule 3 For any other situation, the alignment is specified by the most
recent alignment pragma with no tag identifier.
The compiler generates warnings for the following condition:
• When an alignment pragma redefines the alignment for a specific
structure tag name:
#pragma align xyz=4
#pragma noalign xyz
Examples
The following examples show different ways nested structures can be
aligned:
#pragma noalign (outer1) /* Both outer1 and inner1 are */
#pragma noalign (inner1) /* packed (aligned on */
struct outer1 { /* 1-byte boundaries). */
struct inner1 {
short s1;
char c1;
} si1;
int i2;
};
#pragma noalign (outer2) /* outer2 is packed. */
struct outer2 {
struct inner2 {/* Since the inner structure has a tag */
short s2; /* (inner2) but no alignment specified,*/
char c2; /* alignment of inner2 uses the default*/
} si1; /* alignment. The short s2 aligns on */