1
The specific syntax being used is GCC specific. ANSI C (1999 standard)
2
has variable argument macros with a different syntax (which modern GCC
6
#define P_VAR(output, string, args...) \
7
fprintf (output, "This is "string"\n", ##args)
9
The "##" in the above macro is GCCs method of dealing with the case where
10
the variable part of the macro is empty. It has the effect of deleting the
11
comma just prior to the "##" when args is empty.
14
ANSI C and new GCC syntax
15
#define P_VAR(output, ...) \
16
fprintf (output, "This is "string"\n", __VA_ARGS__)
18
This definition of P_VAR has the identical expansion as the previous
20
of P_VAR. Both require a minimum of 2 parameters when being expanded.
22
The Old GCC version has the advantage that it's closer to what you expect
23
from experience with printf() and company, but suffers from the kludge
24
needed when the variable part of the macro is empty.
26
The ANSI C version doesn't have the "empty kludge", but requires one more
27
parameter than the number of named parameters. For example let's say that
28
I want to create a "log" macro that is used in the exact same fashion as
29
printf() except it sends all output to log_file instead of stdout. The
30
desired macro would look like:
32
#define log(...) fprintf(log_file, __VA_ARGS__)
34
And yes, the log macro would require at least 1 parameter in order to be
35
legal just as printf() requires at least 1 parameter.
37
Using the old GCC style the macro would be
39
#define log(format, args...) fprintf(log_file, format, ##args)
41
I would suggest that you use the new ANSI method of variable argument macros
42
instead of the old GCC style since it is likely to be supported by more
43
compilers in the future