我可以定义在中间,而不是结束与__VA_ARGS可变参数çpreprocessor宏? [英] Can I define variadic C preprocessor macros with __VA_ARGS in the middle instead of the end?
问题描述
GCC抱怨,如果我这样做:
GCC complains if I do this:
#define M(obj,met, ..., contents) obj##_##met(const void * self, __VA_ARGS__) { \
contents \
}
给予我这些原因有二:
Giving me these 2 reasons:
error: missing ')' in macro parameter list
warning: __VA_ARGS__ can only appear in the expansion of a C99 variadic macro
显然,C99 - 款式复杂的宏期待右括号省略号后立即,有效地要求一个可变列表是宏的最后一个参数。我需要它在中间,以在上面的宏描述了我的速记符号。 GCC是否支持此功能,使用其他(非C99)可变参数宏的风格?我可以模仿它做别的好歹?我不想在最后的可变参数列表,它会让我的符号混淆。我只能使用GCC。
Apparently, C99 - style variadic macros expect the closing parenthesis immediately after the ellipsis, effectively demanding that the variadic list be the last arguments of the macro. I need it to be in the middle to produce my shorthand notation described in the above macro. Does GCC support this feature, using another (non-C99) variadic macro style? Can I emulate it doing it someway else? I don't want the variadic list at the end, it will make my notation confusing. And I can only use GCC.
推荐答案
没有你不能。在 ...
必须出现在最后。
No you can't. The ...
must appear at the end.
但是,你可以定义 M
为
#define M(obj,met, ...) obj##_##met(const void * self, __VA_ARGS__)
和使用它作为
void M(foo, bar, int x, char y, double z) {
content;
}
这篇关于我可以定义在中间,而不是结束与__VA_ARGS可变参数çpreprocessor宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!