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

Mixed-Language Programming for TNS Programs
HP C/C++ Programmer’s Guide for NonStop Systems429301-008
7-29
Extended Data Segments
In the following example, a large-memory-model TNS C routine calls a TAL routine that
manipulates data in an explicit extended data segment and then restores the automatic
extended data segment. When control returns to the TNS C routine, it manipulates
data in the restored automatic extended data segment:
TAL Code
INT .EXT array[0:10]; !Allocated in the automatic
! extended data segment ID 1024D
INT .EXT arr_ptr;
?PUSHLIST, NOLIST, SOURCE $SYSTEM.SYSTEM.EXTDECS0 (
? PROCESS_DEBUG_, DEFINEPOOL, GETPOOL,
? SEGMENT_ALLOCATE_, SEGMENT_USE_, SEGMENT_DEALLOCATE_)
?POPLIST
PROC might_lose_seg;
BEGIN
INT status := 0;
INT old_seg := 0;
INT new_seg := 100;
INT(32) seg_len := %2000D; !1024D
array[0] := 10; !Do work in automatic segment
status := SEGMENT_ALLOCATE_ (
new_seg, seg_len, , , , , arr_ptr);
!Allocate an explicit extended data segment;
!store segment base address in ARR_PTR
IF status <> 0 THEN CALL PROCESS_DEBUG_;
Status := SEGMENT_USE_ (new_seg, old_seg, arr_ptr);
!Make the explicit extended data segment current
IF status <> 0 THEN CALL PROCESS_DEBUG_;
!Use DEFINEPOOL, GETPOOL to retrieve a block in the
! explicit extended data segment.
arr_ptr[2] := 10; !Do some work in the segment.
!When you no longer need the explicit extended data
! segment, call SEGMENT_DEALLOCATE_.
status := SEGMENT_USE_ (old_seg);
!Restore the automatic extended data segment
IF status <> 0 THEN CALL PROCESS_DEBUG_;
END;
C Code
#pragma symbols, inspect, strict
short arr[10];
char sarr[10];
char *s;
_tal void MIGHT_LOSE_SEG (void);