This is the mail archive of the
mailing list for the GCC project.
the problem about different treatment to __VA_ARGS__ when using VS 2008 and GCC
- From: Liu Liu <ll2ef at virginia dot edu>
- To: gcc-help at gcc dot gnu dot org
- Date: Mon, 5 Apr 2010 17:03:00 -0400
- Subject: the problem about different treatment to __VA_ARGS__ when using VS 2008 and GCC
I am trying to identify a problem because of an unusual usage of
variadic macros. Here is the hypothetic macro:
#define va(c, d, ...) c(d, __VA_ARGS__)
#define var(a, b, ...) va(__VA_ARGS__, a, b)
var(2, 3, printf, “%d %d %d\n”, 1);
For gcc, the preprocessor will output
printf("%d %d %d\n", 1, 2, 3)
but for VS 2008, the output is
printf, “%d %d %d\n”, 1(2, 3);
I suspect the difference is caused by the different treatment to
__VA_ARGS__, for gcc, it will first expand the expression to
va(printf, "%d %d %d\n", 1, 2, 3), and treat 1, 2, 3 as the
__VA_ARGS__ for macro va. But for VS 2008, it will first treat b as
__VA_ARGS__ for macro va, and then do the expansion.
Which one is correct interpretation for C99 variadic macro? or my
usage falls into an undefined behavior? Thank you.
+1 650 521 3058