TNS/E Native Application Conversion Guide

Developing a Conversion Strategy
TNS/E Native Application Conversion Guide529659-003
2-7
Converting Programs With Misaligned Data
FIELDALIGN SHARED2 and REFALIGNED 2 directives in pTAL. These pragmas and
directives ensure that the native compilers use the same data alignment as TNS
compilers.
Another strategy is to set the FIELDALIGN CSHARED2 and REFALIGNED 2 pragmas
or the FIELDALIGN SHARED2 and REFALIGNED 2 directives when you first start
converting a program. After the program has been converted to native mode and runs
correctly, you can remove the pragmas or directives and recompile the program. You
can then resolve any problems caused by data misalignment.
The alignment of level-01 and level-77 data items is different in TNS and TNS/E native
COBOL. In TNS COBOL, level-01 and level-77 data items are aligned on a 2-byte
boundary. In TNS/E native COBOL, these items are aligned on an 8-byte boundary.
For consistency with TNS COBOL, you can direct the TNS/E native COBOL compiler
to align level-01 and level-77 items on a 2-byte boundary by adding the
SYNCHRONIZED clause to their declarations.
The data alignment you select depends on whether data is shared. See Section 9,
Converting Programs That Share Data, if data is shared between:
TNS programs and native programs
pTAL programs and native C or C++ programs
For more information on how the native compilers align data, see:
C/C++ Programmer’s Guide
pTAL Conversion Guide
Converting Programs With Misaligned Data
Programs compiled with the TNS and native compilers align data items according to
certain rules. TNS compilers align data on even-byte boundaries, while TNS/R and
TNS/E compilers align 4-byte data items on boundaries whose addresses are a
multiple of 4. TNS/E compilers also align 8-byte data items on 8-byte boundaries.
Additionally, TNS/E native GETPOOL and malloc procedures allocate buffers aligned
on 16-byte boundaries. Occasionally, however, a programming error or a run-time
event causes a data item to violate these alignment rules.
In TNS interpreted or accelerated programs on a TNS/R system, these misaligned
addresses are sometimes rounded down to the next lower even-byte address. This
“round-down” behavior can result in unexpected program behavior, including run-time
errors or incorrect results.
On a TNS/E system, in both TNS interpreted or accelerated programs and in native
programs, misaligned addresses are never rounded down. As a result, TNS program
with misaligned addresses that are rounded down on a TNS/R system might behave
differently when converted to TNS/E native mode (because the misaligned address will
not be rounded down). For this reason, you should ensure that TNS programs on
TNS/R systems do not contain data misalignments before converting them to native
mode.