#pragma align
Purpose
Specifies the alignment of data objects in storage, which avoids performance problems with misaligned data.
Syntax
Parameters
- packed
- Bit field data is packed on a bitwise basis without respect to byte boundaries.
- power
- Uses the RISC System/6000 alignment rules. This is the default.
- natural
- Structure members are mapped to their natural boundaries. This has the same effect as the
power suboption, except that it also applies alignment rules to
doubleandlong doublemembers that are not the first member of a structure or union. - reset
- Discards the current pragma setting and reverts to the setting specified by the previous pragma directive.
Usage
The power suboption is the default to ensure compatibility with existing objects. If compatibility with earlier versions is not necessary, you should consider using natural alignment to improve potential application performance.
The pragmas affect all aggregate definitions that appear after a given pragma directive; if a pragma is placed inside a nested aggregate, it applies only to the definitions that follow it, not to any containing definitions. Any aggregate variables that are declared use the alignment rule that applied at the point at which the aggregate was defined, regardless of pragmas that precede the declaration of the variables. See below for examples.
Examples
/* file2.c The default alignment rule in effect is power */
typedef struct A A2;
#pragma align(packed) /* The packed alignment rule is now in effect */
struct A {
int a;
char c;
}; #pragma align(reset) /* The default alignment rule is in effect again */
struct A A1; /* A1 and A3 are aligned using the power alignment rule since */
A2 A3; /* this rule applied when struct A was defined *//* file2.c The default alignment rule in effect is power */
struct A {
int a;
#pragma align(packed) /* Applies to B; A is unaffected */
struct B {
char c;
double d;
} BB; /* BB uses the packed alignment rule */
} AA; /* AA uses the power alignment rule /* 