Is there a way to use C++ preprocessor stringification on variadic macro arguments?

前端 未结 3 1912
太阳男子
太阳男子 2020-12-06 01:58

My guess is the answer to this question is no, but it would be awesome if there was a way. To clarify, assume I have the following macro:

#define MY_VARIADIC         


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-06 02:31

    This is probably is not very close to what you are wanting, but something like the following might get you there:

    #define MY_VARIADIC_MACRO(X) printf( "%s\n", #X )
    

    Then use it like the following. Enclose the parameters in parens so that it appears as one parameter to the macro.

    MY_VARIADIC_MACRO(( var1, var2, "string" ));

    You could then have the macro call some function that strips off the outer parens or possibly parses the given string.

提交回复
热议问题