在不识别##的编译器上在可变宏上吞吐逗号 [英] Swallowing comma in variadic macros on compilers that do not recognise ##
问题描述
在gcc中,可以通过添加逗号,例如,## ____ VA_ARGS ____
,如 Variadic宏但是,我的编译系统中的编译器(超出我的控制范围)并不理解,## $ b / code>语法,所以不会吞下逗号。
有没有可以使用的解决方法?
谢谢!
是的,gcc吞咽逗号并不标准,您不应该依赖它。
使用符合C99标准的预处理器,您可以通过测试一个空标记的宏参数来获得类似的效果。有关这项工作的想法,您可以在这里,对于一整套预处理宏来说,可以轻松编程这些功能,这里有 P99 。
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!
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.
这篇关于在不识别##的编译器上在可变宏上吞吐逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!