C/C++ Programmer's Guide (G06.25+)

Introduction to HP C and C++ for NonStop Systems
HP C/C++ Programmer’s Guide for NonStop Systems429301-008
1-21
Porting Programs to HP C and C++ for NonStop
Systems
°
System headers
°
Local headers
°
Macros
°
File scope variables
°
External variables
°
External functions
°
Structures and unions
°
Signal-catching functions
°
Functions
°
main function
Do not write code that relies on processor architecture. Be careful when writing
code that relies on word size, pointer size, bit fields, arithmetic precision, byte
order, stack size, stack growth, heap size, and heap growth.
Do not make assumptions about the size and format of any data type:
°
Use type short and type long instead of type int, if possible. In particular,
do not interchange between type int and type long.
°
Do not assign an int to or from a pointer without an explicit type cast.
°
Do not assume that different pointer types are the same.
Use unsigned types for bit fields.
There are many commercially available texts that describe how to write portable
applications in C, including:
Horton, Mark. Portable C Software. Prentice Hall, Inc., 1990.
Jaeschke, Rex. Portability and the C Language. Hayden Books, 1989.
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 information on porting UNIX C and C++ programs to Open System Services, refer
to 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.