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

Mixed-Language Programming for TNS Programs
HP C/C++ Programmer’s Guide for NonStop Systems429301-008
7-20
Variables and Parameters
Multidimensional Arrays
In C, you can declare multidimensional arrays. In TAL, you can emulate
multidimensional arrays by declaring structures that contain arrays.
Here is an example of multidimensional arrays in TAL and TNS C (large-memory
model):
TAL Code C Code
STRUCT rec1 (
*
);
BEGIN
INT y[0:4]; short cma[10][5];
END;
STRUCT .EXT tma(rec1)[0:9];
!Sample access! /* sample access */
tma[8].y[3] := 100; cma[8][3] = 100;
Arrays of Structures
If you specify bounds when you declare a TAL structure, you create an array of
structures. The following TAL and C arrays of structures are equivalent. Each
declaration contains an array of ten structure occurrences:
TAL Code C Code
STRUCT cell (
*
); struct cell
BEGIN {
INT x; short x;
STRING y; char y;
END; };
STRUCT .EXT tcell(cell)[0:9]; struct cell ccell [10];
PROC honey (c); void JOANIE
INT .EXT c (cell); (struct cell *);
EXTERNAL;
Redefinitions and Unions
Variant records are approximated by TAL structure redefinitions and C unions. A TAL
redefinition declares a structure item that uses the same memory location as an
existing structure item. The existing structure item can be a simple variable, array,
substructure, or pointer that:
Begins on a word boundary
Is at the same BEGIN-END level in the structure as the redefinition
Is the same size or larger than the redefinition
A C union defines a set of variables that can have different data types and whose
values alternatively share the same portion of memory. The size of a union is the size
of its largest variable; the largest item need not come first. A union always begins on
a word boundary.