HP aC++/HP C Programmer's Guide (B3901-90036; A.06.26; September 2011)

To enable indirect access to unaligned data that has been assigned to another type, use
the link in the library, -lunalign and arm the appropriate signal handler with a call
to allow_unaligned_data_access. This causes every signal generated due to
unaligned access to be intercepted and handled as expected. It also creates significant
run-time overhead for every access to unaligned data, but does not impact access to
aligned data.
Implicit Access to Unaligned Data
Calls to non-static member functions require that an implicit this pointer be passed to
these functions, which can then indirectly access data through this implicit parameter. If
such an access is to unaligned data, the situation in the prior example occurs.
Furthermore, virtual function calls often require indirect access to a hidden field of a class
that could be unaligned under the influence of the #pragma pack directive.
If you are passing the address of a field to other code, consider the following example.
Unless compiled with -DRECOVER on the command line and linked with -lunalign,
the following example is likely to prematurely terminate with a bus error:
#include <stdio.h>
#ifdef RECOVER
extern C void allow_unaligned_data_access();
#endif
#pragma pack 1
struct PS1 {
PS1();
~PS1();
private:
char c;
int a;
};
#pragma pack
PS1::PS1(): a(1) { // There appears to be no pointer, but there
// is an unaligned access, possibly through this.
printf(In constructor.\n);
}
PS1::~PS1() {
a = 0; // Misaligned access, possibly though this
printf(In destructor.\n);
}
int main() {
#if defined(RECOVER)
allow_unaligned_data_access();
#endif
PS1 s;
}
Data Alignment Pragmas 123