HP C Programmer's Guide (92434-90009)

Chapter 2 25
Storage and Alignment Comparisons
Alignment Rules
In the first typedef, my_ptr will be a 4-byte aligned pointer to a 2-byte aligned int. The
second typedef will create another type for my_ptr which is now 2-byte aligned, since
my_double_ptr is derived from my_ptr.Somy_double_ptr is a 4-byte aligned pointer to a
2-byte aligned pointer which points to a 2-byte aligned int.
Similar declarations inside a structure will not have the same resulting alignment.
Consider the following declaration:
#pragma HP_ALIGN NOPADDING
typedef int **my_double_ptr;
struct s {
int **p;
};
In the above example, my_double_ptr is a 4-byte aligned pointer type pointing to another
4-byte aligned pointer which points to a 1-byte aligned int. However, struct s member p
is a 1-byte aligned pointer which points to a 4-byte aligned pointer which points to 4-byte
aligned int. Inside a structure, the member itself is affected by the alignment mode.
However, with a typedef, the typedef name is not directly affected. The innermost type
from which the typedef name is derived is affected by the alignment mode.