C/C++ Programmer's Guide (G06.27+, H06.03+)

Table Of Contents
Handling TNS Data Alignment
HP C/C++ Programmer’s Guide for NonStop Systems429301-010
23-7
C/C++ Misalignment Examples
8. Addressing an external data item that contains misaligned parts (as short or
larger items)
If a TNS program uses external data items (files or structures) that have
misaligned parts (such as those on computer systems that have no data alignment
requirements), it must declare and directly access them as char arrays rather than
as short or larger items. See Example 23-6 on page 23-10.
9. Using string check-sum or hashing functions that use 16-bit or 32-bit ADD or XOR
operations
Some TNS programs use check-sum or hashing functions that use a series of 16-
bit or 32-bit ADD or XOR operations to reduce an arbitrary length byte string to 16
or 32 bits. If the string begins on an even-byte boundary, this is often coded as an
array of short or int elements overlaying the byte string, but if the string can
begin at an arbitrary address, the loop must not use short * or int * pointers.
See Example 23-7 on page 23-10.
10. Storing the length of a byte string in its first two bytes
If the string can begin at an arbitrary address, the two bytes in which the length is
stored must be stored and accessed as separate bytes, not as a single short
integer. See:
Example 23-2 on page 23-8
Example 23-3 on page 23-9
Example 23-4 on page 23-9
11. Ending a byte string with multiple zero-filled bytes
The zero-filled bytes must be inserted by separate single-byte storage operations,
not by a single short storage operation.