HP C A.06.05 Reference Manual
HP C/HP-UX Implementation Topics
The varargs Macros
Chapter 10256
In the use of a variable arguments macro, a one-to-one correspondence is set up between the
arguments in use and those in its definition. This is up to, but not including, the variable
argument parameter. The rest of the arguments in the use of the macro definition are referred
to as the trailing arguments. For purposes of expanding the macro, the entire combination of
the trailing arguments (including the separating commas) is substituted for the variable
argument parameter in the replacement text.
There are minor usage differences between how C9X and GNU specify variable argument
macros are defined:
• In the GNU style, the name of the variable parameter s precedes the ellipsis in the
parameter list.
• In the C9X standard, the identifier __VA_ARGS__ refers to the variable arguments.
• The identifier __VA_ARGS__ can only occur only in the replacement-list of a function-like
macro that uses the ellipsis notation in the arguments.
Variable names
Variable names are also handled slightly different by C9X and GNU.
For example:
• __VA_ARGS__ in the replacement text indicates the variable name in the following
C9X-style code:
printf(f, __VA_ARGS__)
• s in the replacement text indicates the variable name in the following GNU-style code:
Table 10-3 How C9X and GNU define a variable argument macro
C9X
#define foo(f, ...) printf (f, __VA_ARGS__)
GNU
#define foo(f, s...) printf(f, s)
Table 10-4 How C9X and GNU refer to varargs in macro replacement text
C9X GNU
Specified by the identifier
__VA_ARGS__.
Name appears in the replacement
text.