TNS/E Native Application Conversion Guide

C and C++ Conversion Tasks
TNS/E Native Application Conversion Guide529659-003
3-2
Using the Native C and C++ Compilers
This section assumes your program can be compiled by the current TNS C compiler or
TNS C++ preprocessor. It also assumes your program runs on the current version of
the operating system. See the
C/C++ Programmer’s Guide
for information on
converting C programs to use the current TNS C compiler.
Using the Native C and C++ Compilers
Both the TNS and native C compilers conform to the following ISO/ANSI C language
standards: ISO/IEC 9899:1990 for C, ISO/IEC 9899:1999 for C, and ISO/IEC
14882:1998 for C++. Source code that compiles without warnings or errors with the
TNS C compiler or C++ preprocessor might get warnings or errors using the native C
and C++ compilers. (In most cases, the native compilers are better than the TNS
compilers in detecting violations to the ISO/ANSI C standard.) For example, the native
C and C++ compilers detect these errors that the TNS compilers do not detect:
Characters trailing on a #include line, except nolist.
Incorrect use of a NULL pointer. In C, NULL is defined as zero. In TNS programs,
address 0 exists. If you call a function, such as strlen() with a NULL pointer, the
function does not trap but returns an answer (typically 1). In native C programs,
address 0 does not exist. Such function calls fail, usually with a SIGSEGV. This
user bug is undetected on the TNS architecture.
It is possible, but highly unlikely, that you will need to make changes caused by
differences in the translation limits of the TNS and native compilers.
Program logic or behavior that depends on the knowledge of the underlying machine
architecture or uses undocumented features (mainly privileged features) might require
changes to compile and run correctly using the native compilers.
There is no correlation between either the text or the number of diagnostic messages
produced by the TNS and native compilers.
The TNS C compiler and C++ preprocessor support HP extensions for NonStop
systems to the C and C++ languages by default. The native C and C++ compilers do
not support these HP extensions by default. Specify the EXTENSIONS pragma or the
-Wextensions c89 or c99 flag to direct the native compilers to support these HP
extensions.
In the Guardian environment, the CCOMP command runs the native C compiler, and
the CPPCOMP command runs the native C++ compiler. In the OSS and PC
environments, the native c89 utility runs the native C and C++ compilers, and the
native c99 utility runs the native C compiler . On the PC, the c89 utility can be run
from within ETK.
The c89 and c99 commands for the PC and OSS environments provide an option to
specify the target platform for the compilation: specify -Wtarget=TNS/R to generate
RISC code or -Wtarget=TNS/E to generate Itanium code. The default for the PC is
-Wtarget=TNS/R, and the default for OSS is the same as the host platform. Note that