コンパイラーがファイルのコンパイルに使用する集合体の位置合わせ規則を指定する。このオプションを使用して、ソース・プログラム全体または特定の部分のいずれかについて、クラス型オブジェクトのマップ時に使用する最大の位置合わせを指定します。
使用可能な位置合わせのオプションは、以下のとおりです。
linuxppc コンパイラーは、デフォルト GCC 位置合わせ規則を使用して GCC オブジェクトとの互換性を維持します。これはデフォルトです。 bit_packed コンパイラーは、bit_packed の位置合わせ規則を使用します。このサブオプションは、GCC -fpack-struct オプションとほぼ同じです。
#pragma alignおよび #pragma optionsも参照してください。
コマンド行で -qalign オプションを複数回使用した場合は、最後に指定した位置合わせ規則がファイルに適用されます。
#pragma align=alignment_rule を使用して、-qalign コンパイラー・オプションの設定をオーバーライドすることにより、コードのサブセットの位置合わせを制御できます。直前の位置合わせ規則に復帰するには、 #pragma align=reset を使用します。コンパイラーは、位置合わせディレクティブをスタックします。このため、#pragma align=reset ディレクティブを指定することによって、直前の位置合わせディレクティブの内容が不明であっても、その規則に戻して使用することができます。例えば、インクルード・ファイル内にクラス宣言があり、そのクラスに対して指定した位置合わせ規則をクラスの組み込み先に適用したくない場合に、このオプションを使用することができます。
例 1 - 集合体定義にのみ影響を与える
コンパイラー呼び出しを使用して、以下を実行します。
xlc++ file2.C /* <-- default alignment rule for file is */ /* linuxppc because no alignment rule specified */
ここで、file2.C には以下が含まれます。
extern struct A A1; typedef struct A A2; #pragma options align=bit_packed /* <-- use bit_packed alignment rules*/ struct A { int a; char c; }; #pragma options align=reset /* <-- Go back to default alignment rules */ struct A A1; /* <-- aligned using bit_packed alignment rules since */ A2 A3; /* this rule applied when struct A was defined */
例 2 - #pragma の組み込み
コンパイラー呼び出しを使用して、以下を実行します。
xlc -qalign=linuxppc file.c /* <-- default alignment rule for file */ /* is linuxppc */
ここで、file.c には以下が含まれます。
struct A { int a; struct B { char c; double d; #pragma options align=bit_packed /* <-- B will be unaffected by this */ /* #pragma, unlike previous behavior; */ /* linuxppc alignment rules still */ /* in effect */ } BB; #pragma options align=reset /* <-- A is unaffected by this #pragma; */ } AA; /* linuxppc alignment rules still */ /* in effect */
__align 指定子を使用すると、データ項目を宣言または定義するときの位置合わせを明示的に指定することができます。
__align 指定子を使用して、データ項目を宣言または定義する場合の位置合わせおよび埋め込みを明示的に指定する。
declarator __align (int_const) identifier; __align (int_const) struct_or_union_specifier [identifier] {struct_decln_list}
ここで、
int_const は、バイト整合の境界を指定します。 int_const は、0 より大きく 2 の累乗と等しい整数定数でなければなりません。
__align 指定子は、第 1 レベルの変数および集合体定義の宣言でのみ使用することができます。これは、パラメーターおよび自動を無視します。
__align 指定子は、別の集合体定義の範囲内でネストされた集合体定義に使用することができます。
__align 指定子は、以下の状態で使用することはできません。
すべての位置合わせがオブジェクト・ファイル内で表示可能であるとは限りません。
以下は、__align を第 1 レベルの変数に適用しています。
int __align(1024) varA; /* varA is aligned on a 1024-byte boundary and padded with 1020 bytes */
static int __align(512) varB; /* varB is aligned on a 512-byte boundary and padded with 508 bytes */
int __align(128) functionB( ); /* An error */
typedef int __align(128) T; /* An error */
__align enum C {a, b, c}; /* An error */
以下は、集合体メンバーに影響せずに __align を位置合わせおよび埋め込み集合体の各タグに適用しています。
__align(1024) struct structA {int i; int j;}; /* struct structA is aligned on a 1024-byte boundary with size including padding of 1024 bytes */
__align(1024) union unionA {int i; int j;}; /* union unionA is aligned on a 1024-byte boundary with size including padding of 1024 bytes */
以下は、構造体または共用体を使用している集合体のサイズおよび位置合わせが影響を受けているところで、 __align を構造体または共用体に適用しています。
__align(128) struct S {int i;}; /* sizeof(struct S) == 128 */ struct S sarray[10]; /* sarray is aligned on 128-byte boundary with sizeof(sarray) == 1280 */ struct S __align(64) svar; /* error - alignment of variable is smaller than alignment of type */ struct S2 {struct S s1; int a;} s2; /* s2 is aligned on 128-byte boundary with sizeof(s2) == 256 */
以下は、__align を配列に適用しています。
AnyType __align(64) arrayA[10]; /* Only arrayA is aligned on a 64-byte boundary, and elements within that array are aligned according to the alignment of AnyType. Padding is applied after the back of the array and does not affect the size of the array member itself. */
以下は、変数の位置合わせのサイズが型の位置合わせのサイズと異なるところに __align を適用しています。
__align(64) struct S {int i;}; struct S __align(32) s1; /* error, alignment of variable is smaller than alignment of type */ struct S __align(128) s2; /* s2 is aligned on 128-byte boundary */ struct S __align(16) s3[10]; /* error */
int __align(1) s4; /* error */
__align(1) struct S {int i;}; /* error */
コンパイラーのコマンド行オプション
#pragma align
#pragma pack
また、『集合体内のデータの位置合わせ』も参照してください。