This section discusses information about preprocessing directives that is specific to the C++ compiler.
The preprocessor directive pragma is part of the C++ standard but the form, content, and meaning of pragmas is different for every compiler. See Pragmas for details on the pragmas that the C++ compiler recognizes.
Oracle Developer Studio C++ also supports the C99 keyword _Pragma. The following two invocations are equivalent:
#pragma dumpmacros(defs) _Pragma("dumpmacros(defs)")
To use _Pragma instead of #pragma, write the pragma text as a literal string enclosed in parentheses as the one argument of the _Pragma keyword.
The C++ compiler accepts #define preprocessor directives of the following form.
#define identifier (...) replacement-list #define identifier (identifier-list, ...) replacement-list
If the macro parameter list ends with an ellipsis, an invocation of the macro is allowed to have more arguments than there are macro parameters. The additional arguments are collected into a single string, including commas, that can be referenced by the name __VA_ARGS__ in the macro replacement list.
The following example demonstrates how to use a variable-argument-list macro.
#define debug(...) fprintf(stderr, __VA_ARGS__) #define showlist(...) puts(#__VA_ARGS__) #define report(test, ...) ((test)?puts(#test):\ printf(__VA_ARGS__)) debug(“Flag”); debug(“X = %d\n”,x); showlist(The first, second, and third items.); report(x>y, “x is %d but y is %d”, x, y);
which results in the following:
fprintf(stderr, “Flag”); fprintf(stderr, “X = %d\n”, x); puts(“The first, second, and third items.”); ((x>y)?puts(“x>y”):printf(“x is %d but y is %d”, x, y));
–Dname[=def] in the appendix shows the predefined macros. You can use these values in such preprocessor conditionals as #ifdef.The +p option prevents the automatic definition of the sun, unix, sparc, and i386 predefined macros.
The #error and #warning preprocessor directives can be used to generate compile-time diagnostics.
Issue error diagnostic token-string and terminate compilation
Issue warning diagnostic token-string and continue compilation.