宏中的__VA_ARGS__是什么意思? [英] What does __VA_ARGS__ in a macro mean?
问题描述
/* Debugging */
#ifdef DEBUG_THRU_UART0
# define DEBUG(...) printString (__VA_ARGS__)
#else
void dummyFunc(void);
# define DEBUG(...) dummyFunc()
#endif
我已经在C编程的不同头文件中看到了这种表示法,我基本上理解了它在传递参数,但是我不明白这种三点表示法"是什么意思?
有人可以举例说明还是提供有关VA Args的链接?
这是杂色宏.这意味着您可以使用任意数量的参数来调用它.这三个...
类似于C语言中 variadic函数中使用的相同构造. >
这意味着您可以使用这样的宏
DEBUG("foo", "bar", "baz");
或带有任意数量的参数.
__ VA_ARGS__再次引用宏本身中的变量参数.
#define DEBUG(...) printString (__VA_ARGS__)
^ ^
+-----<-refers to ----+
因此DEBUG("foo", "bar", "baz");
将替换为printString ("foo", "bar", "baz")
/* Debugging */
#ifdef DEBUG_THRU_UART0
# define DEBUG(...) printString (__VA_ARGS__)
#else
void dummyFunc(void);
# define DEBUG(...) dummyFunc()
#endif
I've seen this notation in different headers of C programming, I basically understood it's passing arguments, but I didn't understand what this "three dots notation" is called?
Can someone explain it with example or provide links also about VA Args?
It's a variadic macro. It means you can call it with any number of arguments. The three ...
is similar to the same construct used in a variadic function in C
That means you can use the macro like this
DEBUG("foo", "bar", "baz");
Or with any number of arguments.
The __VA_ARGS__ refers back again to the variable arguments in the macro itself.
#define DEBUG(...) printString (__VA_ARGS__)
^ ^
+-----<-refers to ----+
So DEBUG("foo", "bar", "baz");
would be replaced with printString ("foo", "bar", "baz")
这篇关于宏中的__VA_ARGS__是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!