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

Table Of Contents
Mixed-Language Programming for TNS/R and
TNS/E Native Programs
HP C/C++ Programmer’s Guide for NonStop Systems429301-010
8-25
Differences Between Native and TNS Mixed-
Language Programs
To write mixed-language programs that run as both TNS and native processes, you
must consider at least these issues:
Data Models on page 8-25
Memory Models on page 8-25
_far Pointer Qualifier on page 8-25
Extended Data Segments on page 8-25
Data Models
The native C and C++ compilers support only one data model: the 32-bit or wide data
model. The size of int is always 32 bits. If you are writing C or C++ programs that you
want to run as both native and TNS processes, you must write code that expects the
size of type int to be 32 bits. A good program practice is to use short for all 16-bit
integers and int for all 32-bit integers.
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