C/C++ Programmer's Guide (G06.27+, H06.08+, J06.03+)
Variadic Macros
Two variants of variadic macro definitions can be invoked in native C with a variable number of
arguments. To use these extensions, you must compile with extensions enabled.
• One variant of variadic macro is the C9X form, described in section 6.8.3 of the Working
Draft, 1997-11-21, WG14/N794 J11/97-158 of the Proposed ISO C Standard.
For example:
#define D(fmt, ...) printf(fmt, __VA_ARGS__)
/* The "..." matches an arbitrary positive number of macro
arguments that can be referred to by __VA_ARGS__
(includes the separating commas) */
D("%c%s\n" , ’E’, "DG");
/* Expands to "printf("%c%s\n", ’E’, "DG");" */
D("EDG\n");
/* Expands to "printf("EDG\n", );" -- note the extra comma*/
• The other variant of variadic macro is the GNU form, provided by the GNU C compiler. This
variant adds to the C9X form the ability to name the variadic parameter and a special meaning
to the token pasting operator ("##"). When the operator is followed by an empty variadic
argument (named or not), the preceding parameter or continuous sequence of nonwhitespace
characters (not part of a parameter) is erased.
For example:
#define E(fmt, args...) printf (fmt, ## args)
E("%c%s\n", ’E’, "DG");
/* Expands to "printf("%c%s\n", ’E’, "DG");" */
E("EDG\n");
/* Expands to "printf("EDG\n" );" -- no extra comma*/
Feature-Test Macros
The feature-test macros, shown in Table 27 determine whether a particular set of features will be
included from header files. Details about these macros follow this table.
Table 27 Predefined Feature-Test Macros
What It DefinesMacro
Defined when bool is a keyword (that is, when using C++ VERSION2 or
VERSION3 dialect)
_BOOL
Identifiers required to modify C headers for use by C++. (Note double
underscore.) This macro is automatically defined by the c89 or c99 command
when the -Wcplusplus flag is used.
__CPLUSPLUS
Identifier used by the different versions of native C++:__CPLUSPLUS_VERSION
• Has a value of 1 if compiling using the VERSION1 directive (using D40
features).
• Has a value of 2 if compiling using the VERSION2 directive (using D45
features).
• Has a value of 3 if compiling using the VERSION3 directive (using G06.20
features).
Identifiers used by the C compiler running in the Guardian environment_GUARDIAN_HOST
Identifiers required for executing in the Guardian environment_GUARDIAN_TARGET
162 Preprocessor Directives and Macros