HP C Programmer's Guide (92434-90009)

36 Chapter2
Storage and Alignment Comparisons
Aligning Structures Between Architectures
HP C on the Series 300/400
The differences between HP C on the HP 9000 Series 300/400 and HP C on the HP 9000
Series 700/800 and HP 3000 Series 900 are:
On the Series 300/400, a structure is aligned on a 2-byte boundary. On the HP 9000
Series 700/800 and HP 3000 Series 900, it is aligned according to the most restrictive
data type within the structure.
On the Series 300/400, the double data type is 2-byte aligned within structures. It is
8-byte aligned on the HP 9000 Series 700/800 and HP 3000 Series 900.
On the Series 300/400, the long double, available in ANSI mode only, is 2-byte aligned
within structures. The long double is 8-byte aligned on the HP 9000 Series 700/800 and
HP 3000 Series 900.
On the Series 300/400, the enumerated data type is 2-byte aligned in a structure, array,
or union. The enumerated type is always 4-byte aligned on the HP 9000 Series 700/800
and HP 3000 Series 900, unless a sized enumeration is used.
When the sample code fragment is compiled and run, the data is stored as shown in Figure
2-10. on page 38:
a+17 Aligns the short z on a 2-byte boundary.
a+25 Fills out the structure to a 2-byte boundary.
a+26 through a+31 Aligns the double u on an 8-byte boundary. The bit-field s begins
immediately after the previous item at a+41. Two bits of padding is
necessary to align the next byte properly.
a+43 through a+47 Fills out the struct q to an 8-byte boundary.
Table 2-4. Padding on HP 9000 Series 700/800 and HP 3000 Series 900
Padding Location Reason for Padding