Different behavior in visual c++ versus gcc/clang while stringifying parameter which contains comma -
i'm using stringizing operator convert parameter may contains comma passed macro string. know, characters cannot stringified – notably, comma(,) because used delimit parameters , right parenthesis()) because marks end of parameter. use variadic macro pass commas stringizing operator this:
#include <stdio.h> #define test 10, 20 #define make_string(...) #__va_args__ #define string(x) make_string(x) int main() { printf("%s\n", string(test) ); return 0; }
it works fine. occurs me happen without variadic macro, modify macro: #define make_string(x) #x
. compiles fine unexpectedly in visual c++ 2008/2010, , output 10, 20
while gcc/clang give compilation error expected:
macro "make_string" passed 2 arguments, takes 1
so question: visual c++ doing additional work or behavior undefined?
vs in general allows parameters in macros , drops them silently: string(10, 20, 30)
- still works , prints 10
. not case here, pretty means vs don't have error gcc threw @ you.
it's not additional work "merely" difference in substitution order.
Comments
Post a Comment