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

If you do not restore the automatic extended data segment before you manipulate data in it, any
of these actions can result:
An assignment statement is beyond the segment’s memory limit and causes a trap.
All assignments within range occur in the hardware base and limit registers of the automatic
extended segment. Data in the currently active extended data segment is overwritten. The
error is undetected until you discover the discrepancy at a later time.
The TNS C code runs until it accesses an invalid address or accesses an inaccessible library
routine.
You get the wrong data from valid addresses in the explicit extended data segment.
In this 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);
main ()
{
s = &sarr[0];
*s = 'A';
arr[0] = 10;
MIGHT_LOSE_SEG (); /* Call TAL routine, which uses the*/
/* explicit extended data segment */
118 Mixed-Language Programming for TNS Programs