C/C++ Programmer's Guide (G06.25+)
Introduction to HP C and C++ for NonStop Systems
HP C/C++ Programmer’s Guide for NonStop Systems—429301-008
1-20
Following Good Programming Practices
The five feature-test macros that apply to standards compliance are:
The XPG4 specification includes the identifiers required by the POSIX.1 and POSIX.2
standards. Thus, specifying the _XOPEN_SOURCE macro automatically includes the
identifiers included by the _POSIX_C_SOURCE=2 macro.
For more information about feature-test macros, see Feature-Test Macros on
page 12-13.
Following Good Programming Practices
In general, the more you follow good programming practices, the easier it will be to port
your program to other hardware and software environments. A few of the most
important good programming practices are:
•
Use strictly conforming C language features as described in the ISO/ANSI C
standard as much as possible. Isolate HP defined and extended C language
features into specific modules.
•
Use function prototypes.
•
Place all environment-specific function declarations in a common header file, such
as environh.
•
Make sure the type of a function’s actual and formal parameters are the same.
•
Define every function with an explicit return type. Make sure the type of a return
expression is the same as the return type of the function.
•
Write your programs to a template similar to the following:
°
Feature-test macros
_POSIX_C_SOURCE=1 Makes visible identifiers required or permitted by
the POSIX.1 standard.
_POSIX_C_SOURCE=2 Makes visible identifiers required or permitted by
the POSIX.1 and POSIX.2 standards.
_XOPEN_SOURCE Makes visible identifiers required or permitted by
the XPG4 specification. Represents the OSS
compile default.
_XOPEN_SOURCE_EXTENDED=1 Makes visible identifiers specified in the XPG4.2
specification as extensions to the XPG4
specification.
_TANDEM_SOURCE Makes visible the identifiers required or permitted
by extensions made by HP. Represents the
Guardian compile default for the TNS C compiler.
Includes some of the identifiers required by the
XPG4 specification, as well as POSIX.1 and
POSIX.2 standards.