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

Mixed-Language Programming for TNS/R and
TNS/E Native Programs
HP C/C++ Programmer’s Guide for NonStop Systems429301-008
8-18
Considerations When Interfacing to pTAL
To declare compatible pTAL and C arrays:
Use data types and alignments that satisfy both compilers.
Declare pTAL arrays that have a lower bound of 0.
Declare one-dimensional C arrays.
Declare indirect pTAL arrays.
The following are compatible arrays in pTAL and native C:
pTAL Code C Code
INT .EXT robin[0:9]; short robin [10];
INT(32) .EXT gull[0:14]; long gull [15];
STRING .EXT grebe[0:9]; char grebe [10];
Structures
The FIELDALIGN C pragma controls the component layout of structures for
compatibility between TNS and native structure layout and for compatibility with native
mixed-language structure layout. Therefore, you need to:
Use the FIELDALIGN SHARED2 pragma to share data between TNS programs and
native programs.
Use the FIELDALIGN SHARED8 pragma to share data between native C/C++
programs and pTAL programs that run on different platforms. SHARED8 requires
that any filler needed to align fields properly be explicitly declared. The compiler
issues a warning for improperly aligned fields in a SHARED8 structure. (You can
also use the FIELDALIGN PLATFORM pragma to share data between native C/C++
and pTAL programs, but that data cannot be shared with any TNS programs.)
All pTAL and C structures begin on a 16-bit boundary. Following are guidelines for
sharing pTAL and C structures and passing them as parameters:
Specify the same layout for corresponding pTAL and C structures.
Specify compatible data types for each item of both structures.
In pTAL, pass structures by reference.
In C, use the & (ampersand) operator.
Characteristic pTAL Array C Array
Lower bound Any integer Always zero
Dimensions One dimension * One or more dimensions
Direct or indirect Direct or indirect Indirect only
Byte or word addressing STRING arrays and extended
indirect arrays are byte
addressed; all other arrays are
word addressed
Native C and C++ only have
byte addressing
* pTAL structures can emulate multidimensional C arrays, as discussed in Multidimensional Arrays on page 8-19.