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

Table Of Contents
Mixed-Language Programming for TNS/R and
TNS/E Native Programs
HP C/C++ Programmer’s Guide for NonStop Systems429301-010
8-12
Considerations When Interfacing to pTAL
c_code = C_GETPOOL(my_pool,size,&blk_addr);
if (_status_eg(c_code))
return( (short *)blk_addr );
else
return( NULL );
}
Techniques other than this cannot be used on NonStop NS-series systems. For more
details, see the Appendix D of the pTAL Reference Manual.
Sharing Data
Using pointers to share data is easier and safer than trying to match declarations in
both languages. Using pointers also eliminates problems associated with where the
data is placed.
The default code generation for pointer dereferencing operations (REFALIGNED 8)
expects the pointer to contain an address that satisfies the alignment requirements of
the object being pointed to. For example, a 4-byte object should have an address that
is a multiple of 4.
If the object is at an address that does not satisfy its alignment requirements, the
default code generation will cause a compatibility trap. To avoid this, specify the
REFALIGNED 2 C pragma or the REFALIGNED 2 pTAL directive on the pointer to the
object. This will result in code generation that assumes that the dereferenced object is
not properly aligned and will compensate for that.
To share data by using pointers, first decide whether the pTAL module or the C module
is to declare the data:
If the pTAL module is to declare the data, follow the guidelines in Sharing pTAL
Data With C Using Pointers on page 8-13.
If the C module is to declare the data, follow the guidelines in Sharing C Data With
pTAL Using Pointers on page 8-14
If both the pTAL and the C modules are to declare the data, follow the guidelines in
Sharing pTAL Data With C Using BLOCK Declarations on page 8-15 or in Sharing
pTAL Global Data With C/C++ Using BLOCK Declarations on page 8-15.
For 64-bit unsigned data, use the FIELDALIGN pragma to select the data alignment
that is appropriate for the compiler you use:
SHARED2 directs the TNS C, native C, and native C++ compilers to lay out
components using the default TAL compiler alignment rules.
SHARED8 directs the TNS C, native C, and native C++ compilers to lay out
components using the pTAL compiler SHARED8 alignment rules.
FIELDALIGN AUTO is recommended when the data layout is target independent and
not shared.