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

Lapin, J. E. Portable C and UNIX System Programming. Rabbit Software, 1987.
Rabinowitz, Henry, and Chaim Schaap. Portable C. Prentice Hall, Inc., 1989.
Porting Programs to HP C and C++ for NonStop Systems
HP C complies with the ISO/ANSI C standard. Any C program that strictly conforms with this
standard and does not use features beyond this standard can immediately be compiled in HP C.
Programs written in Common-Usage C (also called Kernighan and Ritchie C or K&R C) can also
be compiled with the native C compiler.
For more details on porting UNIX C and C++ programs to Open System Services, see the Open
System Services Porting Guide.
It is impossible to provide a complete set of guidelines on porting programs to ISO/ANSI C, but
most porting issues have one of two solutions:
Replace nonstandard function calls with one or more functions from the ISO/ANSI C standard.
In the OSS environment, you can also use many function calls defined in the POSIX.1 and
POSIX.2 standards and the XPG4 specification.
Redesign the code to use functions and features of ISO/ANSI C.
Many UNIX compilers now comply with the ISO/ANSI C standard. Unlike the HP C compilers,
most of these compilers do not strictly enforce the standard by default. These compilers allow
features that do not comply with the standard but that the compilers can still process correctly.
Therefore, many programs that you thought to be compliant are not.
To compile standard-compliant programs with the native C compiler, specify the pragma KR (for
Kernighan & Ritchie or Common-Usage C). To compile such programs with the TNS C compiler,
first convert the programs to ISO/ANSI C in their original environment. The documentation for
these compilers often describes the specific changes required to make a program comply with
ISO/ANSI C.
These commercially available texts describe writing programs that comply with the ISO/ANSI C
standard and porting from Common-Usage C to ISO/ANSI C:
Harbison, Samuel P. and Guy L. Steele. C, A Reference Manual. Prentice Hall, Inc., 1991.
Kernighan, Brian W. and Dennis M. Ritchie. The C Programming Language. Prentice Hall,
Inc., 1988.
Strake, David. C Style: Standards and Guidelines. Prentice Hall, Inc., 1992.
ANSI C Transition Guide. Prentice Hall, Inc., 1990.
Porting Without Data Alignment Problems
Chapter 8: Mixed-Language Programming for TNS/R and TNS/E Native Programs, and Chapter 22:
Handling TNS Data Alignment, provide guidance on the use of compiler pragmas to avoid data
alignment problems when sharing data between programs in different compiler languages or when
porting programs and data between HP development environments or between NonStop platforms.
You can also use the Data Definition Language (DDL) to define data structures in a manner that
minimizes data alignment problems. DDL can be used to describe Enscribe data file structures or
to generate source code with data-object filler appropriate for various compiler data alignment
pragmas. For more details, see the Data Definition Language (DDL) Reference Manual.
Guardian and OSS Environment Interoperability
Open System Services (OSS) is an alternative to the Guardian interface through which users and
programs can interact with the NonStop OS. The main purpose of Open System Services is to
provide an open interface to the operating system for supporting portable applications.
Porting Programs to HP C and C++ for NonStop Systems 47