HP 3000 Manuals

Using Name Spaces in HP C and ANSI C [ HP C Programmer's Guide ] MPE/iX 5.0 Documentation


HP C Programmer's Guide

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 LibraryImplementation 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:

[]
On MPE/iX, three name spaces are available:
[]
The name space definitions include the following: ANSI C is the set of names defined in the ANSI C standard. POSIX is the set of names defined in the POSIX 1003.1 standard. These names are a superset of those used by ANSI C. XOPEN is the set of names defined by the XOPEN standard. These names are a superset of those used by POSIX. HP-UX is all names defined in the header files, a superset of XOPEN. MPE/iX is a superset of all names defined in the ANSI C name space.
NOTE The POSIX name space on MPE/iX is available to users who have purchased the POSIX Developer's Kit.
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 program using the defined libraries. Table 5-2. Selecting a Name Space in ANSI Mode -------------------------------------------------------------------------- | | | | | | When using | Use command line | or #define in | Platform | | the | option... | source program | | | name space... | | | | | | | | | -------------------------------------------------------------------------- | | | | | | MPE/iX | -D_MPEXL_SOURCE | #define | MPE/iX Only | | | | _MPEXL_SOURCE | | | | | | | -------------------------------------------------------------------------- | | | | | | HP-UX | -D_HPUX_SOURCE | #define | HP-UX Only | | | | _HPUX_SOURCE | | | | | | | -------------------------------------------------------------------------- | | | | | | XOPEN | -D_XOPEN_SOURCE | #define | HP-UX Only | | | | _XOPEN_SOURCE | | | | | | | -------------------------------------------------------------------------- | | | | | | POSIX | -D_POSIX_SOURCE | #define | HP-UX and MPE/iX | | | | _POSIX_SOURCE | | | | | | | -------------------------------------------------------------------------- | | | | | | ANSI C | default | default | HP-UX and MPE/iX | | | | | | -------------------------------------------------------------------------- In ANSI mode, the default is ANSI C name space. The macro names _POSIX_SOURCE, _XOPEN_SOURCE, _HPUX_SOURCE, and _MPEXL_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 or _MPEXL_SOURCE macro definitions. 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.


MPE/iX 5.0 Documentation