在宏中访问__va_args__的内容(不是函数)
一个人可以使用...
的内容使用stdarg.h
:
void fn(int nargs, ...){
va_list args; va_start(args,nargs);
i64 arg0 = va_arg(args,i64);
va_end(args);
}
我知道使用__ va_args __
的唯一方法是通过它到另一个宏或最终是一个函数。例如。
#define __fn(...) fn(number_of_args(__VA_ARGS__), __VA_ARGS__)
但是我想知道是否可以在宏本身中“解开” __ va_args __
的值。类似va_start()
,va_arg()
和va_end()
,但对于宏。
One can access the contents of ...
inside a function using stdarg.h
:
void fn(int nargs, ...){
va_list args; va_start(args,nargs);
i64 arg0 = va_arg(args,i64);
va_end(args);
}
The only way I know of using __VA_ARGS__
is to pass it to another macro or, eventually, a function. Eg.
#define __fn(...) fn(number_of_args(__VA_ARGS__), __VA_ARGS__)
but I wonder if it's possible to "unpack" the values of __VA_ARGS__
within a macro itself. Something like va_start()
, va_arg()
, and va_end()
, but for macros.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您可以获取
#define head(x,...)x
的x ,并在列表上迭代eval(evar(...
递归扩展) 。 pfultz2/cloak/wiki/c-preprocessor-tricks,-tips, - 和idioms。 扩展,因此我更喜欢为每个参数明确过载。
Yes, you can get the head
#define HEAD(x, ...) x
of the pack and iterate over the list withEVAL(EVAL(...
recursive expansion. See https://github.com/pfultz2/Cloak/wiki/C-Preprocessor-tricks,-tips,-and-idioms .I find overloading on the number of macro arguments to produce way more readable error messages than
EVAL(EVAL(..
expansions, so I prefer explicitly overloading for each argument.