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

Memory Models
The native C and C++ compilers support the large-memory model.
The TNS C compiler supports the small-memory model or the large-memory model, depending on
the amount of data storage required. However, the large-memory model is recommended and is
the default setting.
The size of a pointer in the large-memory model is 32 bits. The size of a pointer in the small-memory
model is 16 bits.
If you are writing native C or C++ programs that you want to run as both native and TNS processes,
you need to write programs that use the large-memory model.
_far Pointer Qualifier
For native C and C++, there is no need to specify the _far pointer qualifier because the native
compilers support only the large-memory model.
For TNS C, you must use the _far pointer qualifier in the parameter-type-list of an interface
declaration to specify a parameter type that is defined in TAL as an extended pointer using .EXT.
For example:
_tal _variable _cc_status PROC_3 (short _far *);
If you are writing native C or C++ programs that you want to run as both native and TNS processes,
you need to include the _far pointer qualifiers. The native C and C++ compilers accept the _far
specifier for compatibility with the TNS compilers.
Extended Data Segments
When the user data segment (TNS processes) or globals area (native processes) does not provide
enough data space for your process, you can make additional virtual memory available to the
process. Virtual memory is allocated as one or more extended data segments. There are two types
of extended data segments: flat segments and selectable segments. Selectable segments are a
carryover from TNS system architecture. They continue to be supported on native systems. However,
programs written for native systems should use flat segments.
The term “extended” has little significance in the context of native systems. The only non-extended
data segment in user address space is the user data segment of a TNS process, and there are no
non-extended data segments in a native process.
For more details on using extended data segments, see the “Managing Memory” section in the
Guardian Programmer’s Guide.
Interfacing to Native COBOL
Your native C/C++ programs can call functions written in native COBOL.
The general procedure consists of these steps:
Use a native COBOL compiler to compile the COBOL function.
Use a native C/C++ compiler to compile the C/C++ program.
Use eld, ld, or nld to link the object files and create the executable.
140 Mixed-Language Programming for TNS/R and TNS/E Native Programs