HP C Programmer's Guide (92434-90009)

144 Chapter5
Programming for Portability
Using Name Spaces in HP C and ANSI C
Using Name Spaces in HP C and ANSI C
The ANSI standard specifies exactly which names (for example, variable names, function
names, type definition names) are reserved. The intention is to make it easier to port
programs from one implementation to another without unexpected collisions in names. For
example, since the ANSI C standard does not reserve the identifier open, an ANSI C
program may define and use a function named open without colliding with the
open(2)
system call in different operating systems.
HP Header File and Library Implementation of Name Spaces
The HP header files and libraries have been designed to support several different name
spaces. On HP-UX systems, four name spaces are available:
Figure 5-5.
The HP library implementation has been designed with the assumption that many
existing programs will use more routines than those allowed by the ANSI C standard.
If a program calls, but does not define, a routine that is not in the ANSI C name space (for
example, open), then the library will resolve that reference. This allows a clean name
space and backward compatibility.
The HP header file implementation uses preprocessor conditional compilation directives to
select the name space. In non-ANSI mode, the default is the HP-UX name space.
Compatibility mode means that virtually all programs that compiled and executed under
previous releases of HP C on HP-UX continue to work as expected. The following table
provides information on how to select a name space from a command line or from within a