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

Memory Models
A TNS C program can use the small-memory model or the large-memory model, depending on the
amount of data storage required. The large-memory model is recommended and is the default
setting. All examples in this subsection illustrate the large-memory model unless otherwise noted.
A TAL program can use any of these memory combinations, depending on the application’s needs:
The user data segment
The user data segment and the automatic extended data segment
The user data segment and one or more explicit extended data segments
The user data segment, the automatic extended data segment, and one or more explicit
extended data segments
This table describes some aspects of memory usage by C and TAL programs. The far right column
refers to the upper 32K-word area of the user data segment.
Upper 32K-Word AreaData StorageAddressingMemory ModelLanguage
Reserved32K words16-bitSmallTNS C
Reserved127.5 MB32-bitLargeTNS C
Reserved only if you use
the CRE
64K words (without the
CRE), plus 127.5 MB in
16-bit or 32-bitN.A.TAL
each extended data
segment that is allocated
Any TAL module that uses the upper 32K-word area of the user data segment cannot run within a
TNS C object file that contains the main routine.
Data Model
The size of the C data type int is 16 bits in the 16-bit data model and 32 bits in the 32-bit data
model. (The 32-bit data model is also called the wide-data model.) If you specify the 32-bit data
model, the C data type int is 32 bits and the TAL data type INT corresponds to the C data type
short.
Any interface to a TAL routine must be specified in such a way that there is no possibility for a
data-length mismatch. Therefore, in your C program, use short for a 16-bit integer and long
for a 32-bit integer and avoid the use of int. Using short in your C program enables you to
use the same declarations regardless of the data model your program uses. The type short is
always a 16-bit integer in the C compiler.
Calling TNS C Routines From TAL Modules
A TAL module must include an EXTERNAL procedure declaration for each TNS C routine to be
called. This TAL code shows the EXTERNAL procedure declaration for C_FUNC and a routine that
calls C_FUNC. ARRAY is declared with .EXT, because C_FUNC uses the large-memory model:
TAL Code C Code
INT status := 0; short C_FUNC(char *str)
STRING .EXT array[0:4]; {
*str = 'A';
INT PROC c_func (a) str[2] = 'C';
LANGUAGE C; return 1;
STRING .EXT a; }
EXTERNAL;
PROC example MAIN;
BEGIN
Interfacing to TAL 103