HP C Programmer's Guide (92434-90009)

34 Chapter2
Storage and Alignment Comparisons
Aligning Structures Between Architectures
Figure 2-7. Comparison of HPUX_WORD and HPUX_NATURAL Byte Alignments
In the HPUX_WORD alignment mode, six bytes are written to myfile. The integer field2
begins on the third byte. In the HPUX_NATURAL alignment mode, eight bytes are written to
myfile. The integer field2 begins on the fifth byte.
Examples of Structure Alignment on Different Systems
The code fragment in <Undefined Cross-Reference> can be used to illustratethe alignment
on various systems.
Figure 2-8. Code Fragment for Comparing Storage and Alignment
struct x {
char y[3];
short z;
char w[5];
};
struct q {
char n;
struct x v[2];
double u;
char t;
int s:6;
char m;
} a = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,
20.0,21,22,23};
HP C/HP-UX Series 700/800 and HP C/iX
Figure 2-9. on page 36 shows how the data in Figure 2-8. on page 34 is stored in memory
when using HP C on the HP 9000 Series 700/800 and HP 3000 Series 900. The values are