Open System Services Porting Guide (G06.29+, H06.06+, J06.03+)
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 Information” (page 18) 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.
• Do not assume that different pointer types are the same.
• Use unsigned types for bit fields.
Beginning with the H06.24 and J06.13 RVUs, 64-bit OSS applications are supported and HP
recommends following 64-bit programming guidelines. For information about these guidelines,
see the 64-Bit Support in OSS and Guardian chapter in the Open System Services Programmer's
Guide. Additionally, 64-bit OSS processes have their global data and stack in 32-bit addressable
space. As a consequence, there might be issues porting 64-bit applications that have massive static
data or stack requirements. That is, it might be necessary to move large aggregate data from
116 Porting UNIX Applications to the OSS Environment