Using commas inside a macro without parenthesis: How can I mix and match with a template?

后端 未结 3 1366
终归单人心
终归单人心 2020-12-09 21:57

Consider a simple macro:

#define ECHO(x) x

ECHO(foo(1, 2))

This produces the exact output we expect:

foo(1, 2)
         


        
3条回答
  •  情深已故
    2020-12-09 22:00

    #define COMMA ,
    ECHO(template)
    

    A little painful, but it works.

    FWIW, if the syntax for the argument allows ()s, you don't need the substitution, e.g.,

    ECHO((a, b))
    

    will work for a single argument macro but that doesn't work in all cases (including yours).

提交回复
热议问题