Using alignment modes

Each data type that is supported by XL C/C++ is aligned along byte boundaries according to platform-specific default alignment modes. The default alignment mode is linuxppc.

Each of the valid alignment modes is defined in Table 1, which provides the alignment value, in bytes, for scalar variables of all data types.

Table 1. Alignment settings (values given in bytes)
Data type Storage Alignment setting
linuxppc bit_packed
_Bool (C), bool (C++) 1 1 1
char, signed char, unsigned char 1 1 1
wchar_t 4 4 1
int, unsigned int 4 4 1
short int, unsigned short int 2 2 1
long int, unsigned long int 8 8 1
long long 8 8 1
float 4 4 1
double 8 8 1
long double 16 16 1
pointer 8 8 1
vector types 16 16 1
If you generate data with an application on one platform and read the data with an application on another platform, it is recommended that you use the bit_packed mode, which results in equivalent data alignment on all platforms.
Notes:
  • Vectors in a bit-packed structure might not be correctly aligned unless you take extra action to ensure their alignment.
  • Vectors might suffer from alignment issues if they are accessed through heap-allocated storage or through pointer arithmetic. For example, double my_array[1000] __attribute__((__aligned__(16))) is 16-byte aligned while my_array[1] is not. How my_array[i] is aligned is determined by the value of i.

Alignment of aggregates discusses the rules for the alignment of entire aggregates and provides examples of aggregate layouts. Alignment of bit-fields discusses additional rules and considerations for the use and alignment of bit fields and provides an example of bit-packed alignment.



Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us