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

Table Of Contents
Mixed-Language Programming for TNS Programs
HP C/C++ Programmer’s Guide for NonStop Systems429301-010
7-22
Variables and Parameters
Here are examples of TAL and TNS C structure pointers (large-memory model) that
implement a linked list:
TAL Code C Code
STRUCT rec (
*
); struct rec
BEGIN {
INT x; short x;
INT .EXT strptr (rec); struct rec *p;
END; };
STRUCT .EXT joe (rec); struct rec joe;
PROC callme (param1); void f1 (struct rec *);
INT .EXT param1 (rec);
EXTERNAL;
Enumeration Variables
Using C enumeration variables, you can associate a group of named constant values
with an int variable. A C enumeration variable occupies 16 bits of memory. You define
all integer operations on them. The C compiler provides no range checking, so an
enumeration variable can hold a value not represented in the enumeration.
A TNS C routine can share an enumeration variable with TAL routines. A TAL routine
cannot access the enumeration variables, but it can declare LITERALs for readability.
For example:
TAL Code C Code
LITERAL no = 0, enum choice {no = 0,
yes = 3, yes = 3,
maybe = 4; maybe = 4 };
BLOCK answer; enum choice ANSWER;
INT answer_var;
END BLOCK;
A TNS C routine can pass enumeration parameters to TAL routines, placing the actual
value in a TAL INT variable. For example:
TAL Code C Code
LITERAL no = 0, enum choice {no = 0,
yes = 3, yes = 3,
maybe = 4; maybe = 4 };
enum choice answer;
PROC tal_proc (n);
INT n; _tal void TAL_PROC (short);
BEGIN
!Lots of code main ()
IF n = yes THEN ... ; {
!Lots of code answer = yes;
END; TAL_PROC (answer);
/* lots of code */
}