The aligned variable attribute (IBM extension)
With the
aligned variable
attribute, you can override the default memory alignment mode to specify
a minimum memory alignment value, expressed as a number of bytes,
for any of the following types of variables: - Non-aggregate variables
- Aggregate variables (such as a structures, classes, or unions)
- Selected member variables
The alignment_factor is the number of bytes,
specified as a constant expression that evaluates to a positive power
of 2. On the z/OS® platform, the maximum supported value is 8 bytes in 32-bit
mode, and 16 bytes in 64-bit mode. If you omit the alignment factor
(and its enclosing parentheses), the compiler automatically uses the
platform maximum. If you specify an alignment factor
greater than the maximum, the compiler issues an error
message and the compilation fails.
When you apply
the aligned attribute to a member
variable in a bit field structure, the attribute specification
is applied to the bit field container. If the default alignment
of the container is greater than the alignment factor, the default
alignment is used.
Example
In the following
example, the structures
first_address and second_address are set to an alignment of 16 bytes: struct address {
int street_no;
char *street_name;
char *city;
char *prov;
char *postal_code;
} first_address __attribute__((__aligned__(16))) ;
struct address second_address __attribute__((__aligned__(16))) ;In the following example, only the members
first_address.prov and first_address.postal_code are set to an alignment
of 16 bytes: struct address {
int street_no;
char *street_name;
char *city;
char *prov __attribute__((__aligned__(16))) ;
char *postal_code __attribute__((__aligned__(16))) ;
} first_address ;
