HP aC++ A.03.85 Release Notes

HP aC++ Release Notes
New Features in Version A.03.25
Chapter 1 61
If there is an ellipsis (...) in the identifier-list in the macro definition, then the trailing
arguments, including any separating comma preprocessing tokens, are merged to form a
single item: the variable arguments. The number of arguments so combined is such that,
following merger, the number of arguments is one more than the number of parameters in the
macro definition (excluding the ...).
Any __VA_ARGS__ identifier occurring in the replacement list is treated as if it were a
parameter. The variable arguments form the preprocessing tokens used to replace it.
Following are examples:
#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);
Will be expanded to:
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))
For GNU/gcc style coding:
Similar to the variable arguments function described above, a macro can accept a variable
number of arguments. Following is an example:
#define Myprintf(format, args...) \
fprintf (stderr, format, ## args)
Myprintf (“%s:%d: “, input_file_name, line_number)
Will be expanded to:
fprintf (stderr, “%s:%d: “ , input_file_name, line_number)
Note the use of ## to handle the case when args matches no arguments. In this case, args is
empty, and if there is no ##, the macro expansion could be like the following invalid syntax:
fprintf (stderr, “success!\n” , )
By using ##, the comma is concatenated with empty valued arguments, and is discarded at
macro expansion.