c - Chained macro invocations. Argument in parentheses treated differently? -
#define a(p1, p2, p3, p4) foo(p1, p2, p3, p4) #define b(s) a(p1, p2, (s), p4)
here, a() macros binding, aimed increase portability should ever need call bar(p1, p2, p3, p4) , not want rewrite whole code base.
now trying define b() make writing easier on me, p1, p2 , p4 have same values. this, however, not work, unless remove parentheses around s. what going on? passing a?
turns out that:
#define foo(p1, p2, p3, p4) p1 ## p2 ## p3 ## p4()
i not sure p4 defined, though, have valid value. so, when pass (s) instead of s, p1p2
instead of p1p2sp4
.
so passing "(" + + ")"? right! , (which concatinates it's inputs simple
p1 ## p2 ## p3 ## p4
) stops before third argument
yes, foo
produces
p1 ## p2 ## ( s ) ## p4
and pasting parentheses p4
resp. p1 ## p2
produces invalid tokens whole thing refused.
for token-pasting, parentheses big no-no.
Comments
Post a Comment