TAL Programmer's Guide

CRE Guidelines for TAL
Mixed-Language Programming
17–42 096254 Tandem Computers Incorporated
Only C, Pascal, or TAL routines can access data in the user heap. To access heap data,
a C, Pascal, or TAL routine assigns the address returned from malloc or NEW to a
pointer and uses the pointer in an expression. All routines that need access to such
data must either:
Use the same data layout
Call a routine that accesses the data for you
COBOL85 and FORTRAN routines access heap data by calling C, Pascal, or TAL
routines.
In the following example, TAL routine DO_IT calls C routine GETSPACE. GETSPACE
gets a block from the heap, stores a value in the first word of the block, and returns to
DO_IT a pointer that points to the data:
C Code
#include <stddef.h> nolist
#include <stdlib.h> nolist
int *GETSPACE (int nbytes)
{ int *p;
p = (int *) malloc (nbytes);
if ( p )
*p = 100;
return p;
}
TAL Code
INT(32) PROC tal_malloc = "GETSPACE" (nbytes) LANGUAGE C;
INT nbytes;
EXTERNAL;
PROC do_it;
BEGIN
INT .EXT t_ptr;
@t_ptr := tal_malloc (1000);
IF (@t_ptr = 0d) OR (t_ptr <> 100) THEN
BEGIN
!Handle error ...
END;
END;