Swallowing comma in variadic macros on compilers that do not recognise ##

后端 未结 2 1825
礼貌的吻别
礼貌的吻别 2021-01-14 06:28

I need to write a variadic macro in C which must take zero or more arguments.

In gcc, that can be achieved by adding \"##\" after the comma, e.g. ,##____VA_ARG

2条回答
  •  情深已故
    2021-01-14 06:43

    Yes, gcc swallowing the comma is non standard and you should not rely on that.

    With C99 conforming preprocessors you may achieve a similar effect by testing for a macro arguments that is the empty token. For the ideas of how this works you could see here, for a whole set of preprocessor macros that ease the programming of such features there is P99.

提交回复
热议问题