align

Option Type Default Value #pragma options C C++
-qoption align=full ALIGN=suboption x x

Syntax

    -qalign=suboption 
    ALIGN=suboption 

Purpose
Specifies what aggregate alignment rules the compiler uses for file compilation. Use this option to specify the maximum alignment to be used when mapping a class-type object, either for the whole source program or for specific parts.

Notes
The -qalign suboptions are:

power The compiler uses the RISC System/6000 alignment rules.
full The compiler uses the RISC System/6000. alignment rules. The power option is the same as full.
mac68k The compiler uses the Macintosh** alignment rules.
twobyte The compiler uses the Macintosh alignment rules. The mac68k option is the same as twobyte.
packed The compiler uses the packed alignment rules.
bit_packed The compiler uses the bit_packed alignment rules. Alignment rules for bit_packed are the same as that for packed alignment except that bitfield data is packed on a bit-wise basis without respect to byte boundaries.
natural The compiler maps structure members to their natural boundaries. This has the same effect as the power suboption, except that it also applies alignment rules to doubles and long doubles that are not the first member of a structure or union.

If you use the qalign option more than once on the command line, the last alignment rule specified applies to the file.

Within your source file, you can use #pragma options align=reset to revert to a previous alignment rule. The compiler stacks alignment directives, so you can go back to using the previous alignment directive, without knowing what it is, by specifying the #pragma align=reset directive. For example, you can use this option if you have a class declaration within an include file and you do not want the alignment rule specified for the class to apply to the file in which the class is included.

You can code #pragma options align=reset in a source file to change the alignment option to what it was before the last alignment option was specified. If no previous alignment rule appears in the file, the alignment rule specified in the invocation command is used.

Example 1 - Imbedded #pragmas
Using the compiler invocation:

xlC -qalign=mac68k file.c  /* <-- default alignment rule for file is */
                           /*    Macintosh                           */

Where file.c has:

struct A {
  int a;
  struct B {
    char c;
    double d;
#pragma options align=power /* <-- B will be unaffected by this       */
                            /*     #pragma, unlike previous behavior; */
                            /*     Macintosh alignment rules still    */
                            /*     in effect                          */
  } BB;
#pragma options align=reset /* <-- A unaffected by this #pragma;      */
} AA;                       /*     Macintosh alignment rules still    */
                            /*     in effect                          */

Example 2 - Affecting Only Aggregate Definition
Using the compiler invocation:

xlC file2.c /* <-- default alignment rule for file is                 */
            /*     RISC System/6000 since no alignment rule specified */

Where file2.c has:

extern struct A A1;
typedef struct A A2;

#pragma options align=packed /* <-- use packed alignment rules        */
struct A {
  int a;
  char c;
};
#pragma options align=reset /* <-- Go back to default alignment rules */

struct A A1;  /* <-- aligned using packed alignment rules since       */
A2 A3;        /*     this rule applied when struct A was defined      */


List of Batch Compiler Options and Their Defaults
Options that Define the Compiler Object Code Produced
__align Specifier
RISC System/6000 Alignment Rules
Macintosh and Twobyte Alignment Rules
Packed Alignment Rules
Alignment Rules for Nested Aggregates
Equivalent Batch Compile-Link and Incremental Build Options