COBOL Manual for TNS and TNS/R Programs
Migrating TNS Programs to Native Programs
HP COBOL Manual for TNS and TNS/R Programs—522555-006
33-10
Causes of Misalignment in HP COBOL Programs
Causes of Misalignment in HP COBOL Programs
In native HP COBOL programs, misaligned addresses might slow down program
execution, but the misaligned addresses are never “rounded down” and do not cause
the program to terminate abnormally.
In TNS HP COBOL programs, reference parameters and the targets of pointers to
BINARY or COMPUTATIONAL data items must be aligned on 2-byte memory
boundaries for correct operation. The results of odd-byte addresses depend on the
specific NonStop server and the system configuration, but they might include erratic
“rounding down” and abnormal program termination.
In a TNS HP COBOL program, some actions that can cause misaligned addresses
are:
•
Using the POINTER data type and explicit pointer operations
These are rarely used HP extensions to COBOL. Their potential problems are the
same as those of pointers and pointer operations in C/C++ and TAL (see C/C++
Programmer’s Guide and TAL Programmer’s Guide Data Alignment Addendum).
•
Using incompatible descriptions of corresponding REFERENCE parameters in a
calling program and a called program
This situation is the most likely cause of misaligned addresses in HP COBOL
programs. If the called program's Linkage Section describes a REFERENCE
parameter as a group containing BINARY or COMPUTATIONAL data items, the
calling program must describe the corresponding actual parameter in an equivalent
way. If identical descriptions are not possible, the calling program must describe
the actual parameter as a level-01 or level-77 data item so that it is aligned. The
calling program must not describe the actual parameter as an unstructured
alphanumeric data item within a larger group, because then the compiler cannot
prealign the actual parameter as needed. See Example 33-1.
•
Passing an alphanumeric data item or a reference modifier as an actual parameter
If the calling program passes an alphanumeric item or a reference modifier (that is,
a substring from a larger item) as an actual parameter, the called program has two
choices:
°
Describe the corresponding formal parameter as an alphanumeric item (in the
Linkage Section)
°
Copy the bytes of the actual parameter to an aligned group before accessing
any BINARY or COMPUTATIONAL data items
•
Appending a sequence of objects inside an alphanumeric data item
If an HP COBOL program appends a sequence of objects within an alphanumeric
data item, it must ensure that BINARY or COMPUTATIONAL data items (and
records containing them) are aligned on even-byte boundaries; otherwise, the
program must move the objects back to an aligned record before using them.