HP C Programmer's Guide (92434-90009)

130 Chapter5
Programming for Portability
General Portability Considerations
#endif
If this code is compiled on a Series 300/400 system, the first block is compiled; if compiled
on Series 700, the second block is compiled; if compiled on either the Series 700 or the
Series 800, the third block is compiled. You can use this feature to ensure that a program
will compile properly on either Series 300/400 or 700/800.
If you want your code to compile only on the Series 800 but not on the 700, surround your
code as follows:
#if (defined(_ _hp9000s800) &&!defined(_ _hp9000s700))
Series 800-specific code goes here...
#endif
Isolating System-Dependent Code with #include Files
#include files are useful for isolating the system-dependent code like the type definitions
in the previous section. For instance, if your type definitions were in a file mytypes.h, to
account for all the data size differences when porting from system A to system B, you
would only have to change the contents of file mytypes.h. A useful set of type definitions is
in /usr/include/model.h.
NOTE
If you use the symbolic debugger, xdb, include files used within union,
struct, or array initialization will generate correct code. However, such use
is discouraged because xdb may show incorrect debugging information about
line numbers and source file numbers.
Parameter Lists
On the Series 300/400, parameter lists grow towards higher addresses. On the Series
700/800, parameter lists are usually stacked towards decreasing addresses (though the
stack itself grows towards higher addresses). The compiler may choose to pass some
arguments through registers for efficiency; such parameters will have no stack location at
all.
ANSI C function prototypes provide a way of having the compiler check parameter lists for
consistency between a function declaration and a function call within a compilation unit.
lint provides an option (-Aa) that flags cases where a function call is made in the absence
of a prototype.
The ANSI C <stdarg.h> header file provides a portable method of writing functions that
accept a variable number of arguments. You should note that <stdarg.h> supersedes the
use of the varargs macros. varargs is retained for compatibility with the pre-ANSI
compilers and earlier releases of HP C/HP-UX. See varargs(5) and vprintf(3S) for details
and examples of the use of varargs.