The __align specifier lets you specify the alignment of a Data Item or a ILE C/C++ aggregate (such as a struct or union for ILE C, as well as classes for ILE C++). However, __align does not affect the alignment of members within an aggregate, only the alignment of the aggregate as a whole. Also, because of restrictions for certain members of an aggregate, such as 16-byte pointers, the alignment of an aggregate is not guaranteed to be aligned in memory on the boundary specified by __align. For example, an aggregate that has a 16-byte pointer as its only member cannot have any other alignment other than 16-byte alignment because all 16-byte pointers must be aligned on the 16-byte boundary.
>>-declarator--__align--(--+----+--)--identifer--;------------->< +-1--+ +-2--+ +-4--+ +-8--+ '-16-'
>>-struct_specifier--__align--(--+----+--)--+-----------+--{--struct_declaration_list--}--;->< +-1--+ '-identifer-' +-2--+ +-4--+ +-8--+ '-16-'
You can also use the __align specifier to explicitly specify alignment when declaring or defining data items, as shown in some of the examples that follow.
The __align specifier:
_Packed can be associated with struct, union, and in C++, class definitions. It has the same effect as #pragma pack(1). The following are examples of legal and illegal usages of _Packed. In these examples, the keywords struct, union, and class can be used interchangeably.
_Packed class SomeClass { /* ... */ }; // OK typedef _Packed union AnotherClass {} PUnion; // OK typedef _Packed struct {} PAnonStruct; // Illegal, struct must be named _Packed SomeClass someObject; // Illegal, specifier _Packed must be // associated with class definition. _Packed struct SomeStruct { }; // OK _Packed union SomeUnion { }; // OK
unary-expression: __alignof unary-expression __alignof ( type-name )
The __alignof operator returns the alignment of its operand, which may be an expression or the parenthesized name of a type. The alignment of the operand would be determined according to the alignment rule on a specific platform. However, it should not be applied to an expression that has function type or an incomplete type, to the parenthesized name of such a type, or to an expression that designates a bit-field member. The type of the result of this operator should be size_t.
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.