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-21
Variables and Parameters
Pointers
Pointers contain memory addresses of data. You must store an address into a pointer
before you use it. In TAL and C pointer declarations, specify the data type of the data
to which the pointer points. You must use pointers when sharing global variables. You
can pass pointer contents by value between TAL and C routines.
Differences between TAL and C pointers include:
TAL structure pointers can point to a byte or word address.
C structure pointers always point to a word address. To pass a C structure pointer
to a TAL routine that expects a byte structure pointer, you must explicitly cast the C
pointer to type char.
TAL pointers are dereferenced implicitly.
C pointers are usually dereferenced explicitly.
Small-memory-model C routines use 16-bit pointers only.
Large-memory-model C routines use 32-bit pointers only, even if the pointers refer
to the user data segment. In global structure declarations, you must specify
_lowmem in the storage class of the declaration.
If a TAL routine expects a 16-bit pointer, the C pointer you pass must refer to an
object in user data space.
Here are examples of TAL and TNS C pointers (large-memory model):
TAL Code C Code
STRUCT rec (
*
); struct rec
BEGIN {
INT d; short d;
INT .p (rec); struct rec *p;
END; };
BLOCK joe;
INT .EXT joes (rec); struct rec *JOE;
END BLOCK;
PROC tonga (p); void CALEDONIA
INT .EXT p (rec); (struct rec *p)
BEGIN {
!Lots of code /* Lots of code */
END; }
Each language can call the other, passing the address in the pointer by value:
TAL Code C Code
CALL caledonia (joes); TONGA (joe);