HP C Programmer's Guide (92434-90009)

Chapter 5 145
Programming for Portability
Using Name Spaces in HP C and ANSI C
program using the defined libraries.
In ANSI mode, the default is ANSI C name space. The macro names _POSIX_SOURCE,
_XOPEN_SOURCE, and _HPUX_SOURCE may be used to select other name spaces. The name
space may need to be relaxed to make existing programs compile in ANSI mode. This can
be accomplished by defining the _HPUX_SOURCE macro definition.
For example, in HP-UX:
include sys/types.h
include sys/socket.h
results in the following compile-time error in ANSI mode because socket.h uses the
symbol u_short and u_short is only defined in the HP-UX name space section of types.h:
"/usr/include/sys/socket.h", line 79: syntax error:
u_short sa_family;
This error can be fixed by adding -D_HPUX_SOURCE to the command line of the compile.
Table 5-2. Selecting a Name Space in ANSI Mode
When using the
name space…
Use command line
option…
or #define in source program Platform
HP-UX -D_HPUX_SOURCE #define _HPUX_SOURCE HP-UX Only
XOPEN -D_XOPEN_SOURCE #define _XOPEN_SOURCE HP-UX Only
POSIX -D_POSIX_SOURCE #define _POSIX_SOURCE HP-UX
ANSI C default default HP-UX