Open System Services Porting Guide (G06.24+, H06.03+)

Table Of Contents
Porting UNIX Applications to the OSS Environment
Open System Services Porting Guide520573-006
7-11
General Programming Practices
Most UNIX systems provide C compilers that support both ISO/ANSI C and
Common C by using a compiler flag. If your program is written in Common C, it can be
converted to use ISO/ANSI C and tested on the UNIX platform on which it was written
before porting to the OSS environment. A number of commercially available books
contain guidelines for converting programs from Common C to ISO/ANSI C. See
Lewine’s POSIX Programmer’s Guide, which provides general guidelines for dealing
with potentially problematic variations in the C language such as:
Macro replacement and converting macro arguments to strings
Token passing
Name space issues
Function prototypes
New keywords such as const and volatile
String constants
Data type conversions
Character sets
Floating point data
Data structure alignment and layout
See also Related Reading on page xv for a list of other commercially available books
describing good practices when writing C programs that can be easily ported to UNIX
environments.
General Programming Practices
Some good programming practices to use in porting and writing programs are:
Use strictly conforming ISO/ANSI C language features.
Isolate C language features that are defined or extended by HP into specific
modules.
Use function prototypes.
Place all environment-specific function declarations in a common header file.
Make sure the type of a function’s actual and formal parameters are alike.
Define every function with an explicit return type.
Make sure the type of return expression and return type of a function agree.
Do not rely on processor architecture. Be careful to write code that does not rely 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 when possible.
Do not interchange between type int and type long.
Do not assign an int to or from a pointer without an explicit type cast.