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

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. These 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.
In pTAL, a routine cannot return a structure as a return value or pass a struct or union by value.
This pTAL and C structures have compatible layouts:
pTAL Code C Code
STRUCT rec (*); struct birdname
BEGIN {
INT x; short x;
STRING y[0:2]; char y[3];
END; } robin[10];
STRUCT .EXT robin(rec)[0:9];
This pTAL and C structures have compatible layouts:
pTAL Code C Code
STRUCT rec1 (*); struct rec1
BEGIN {
STRING a, b, c; char a, b, c;
END; };
This pTAL and C structures also have compatible layouts:
pTAL Code C Code
STRUCT rec2 (*); struct rec2
BEGIN {
STRING e; char e;
INT y; short y;
STRING g; char g;
END; };
Multidimensional Arrays
In C, you can declare multidimensional arrays. In pTAL, you can emulate multidimensional arrays
by declaring structures that contain arrays.
Here is an example of multidimensional arrays in pTAL and native C:
pTAL Code C Code
STRUCT rec1 (*);
BEGIN
INT y[0:4]; short cma[10][5];
Considerations When Interfacing to pTAL 135