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

♀尐吖头ヾ 提交于 2019-12-01 07:24:53

问题


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_ARGS____ as answered in Variadic macros with zero arguments.

However, the compiler in my build system (beyond my control) does not understand the ,## syntax and so does not swallow the comma.

Is there a workaround I can use?

Thanks!


回答1:


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.



来源:https://stackoverflow.com/questions/8444698/swallowing-comma-in-variadic-macros-on-compilers-that-do-not-recognise

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!