C/C++ Programmer's Guide (G06.25+)

HP C/C++ Programmer’s Guide for NonStop Systems429301-008
23-1
23 Handling TNS Data Alignment
Programs compiled with the TNS instruction set must follow the even-byte data
alignment rules of TNS compilers. Certain violations of these programming rules might
lead to run-time errors. This section describes these violations and explains how to
avoid them and how to diagnose them at run time.
On TNS systems, a word is 16 bits. The TNS instruction set includes data access
instructions that expect 32-bit byte addresses that must be even-byte aligned (that is,
aligned 0 modulo 2) for correct operation. In TNS mode and Accelerator mode,
addresses that are odd-byte aligned (that is, aligned 1 modulo 2) are called misaligned.
TNS processors consistently “round down” misaligned addresses (that is, they ignore
the low-order bit).
TNS/R and TNS/E processors handle misaligned addresses of TNS programs
inconsistently, rounding down some but not others and behaving differently in TNS
mode and accelerated mode. Compilers cannot catch misaligned addresses that are
computed at run time.
The behavior of TNS programs with misaligned addresses on TNS/R or TNS/E
processors is almost impossible to predict. If you are not sure that your program has
only aligned addresses, you can use the tracing facility to detect whether programs are
using misaligned pointers, and if so, where. You should then change the programs to
avoid misalignment.
The round-downs occur only in TNS-compiled C and C++ programs, not in TNS/R or
TNS/E native C or C++ programs. In native mode, misalignments can slow down a
program, but they cannot cause errors.
The data misalignment issue might affect programs that use the following HP products.
If you use these products, see the appropriate manual or addendum:
Product Number Manual or Addendum
TNS C T9255 This manual
TNS C++ T9541 This manual
G-series TNS c89 T8629 This manual
TNS/E c89 T8164 This manual
TNS/E CCOMP T9577 This manual
TNS/E CPPCOMP T9225 This manual
TNS/R c89 T8164 This manual
TNS/R NMC T9577 This manual
TNS/R NMCPLUS T9225 This manual
Accelerator T9276 Accelerator Manual
TNS COBOL85
and OSS cobol
T9257 COBOL Manual for TNS and TNS/R