宏定义 __VA_ARGS__
时间:2009-03-06 来源:朝花夕拾
在jos代码里看到宏__VA_ARGS__
在gcc info里面找到 $ info gcc
然后输入'/__VA_ARGS__'搜索到下面的文字
(其实大部分时候man和info就能解决问题,很多时候我们就是不愿意静下心来读)
5.17 Macros with a Variable Number of Arguments.================================================
In the ISO C standard of 1999, a macro can be declared to accept a
variable number of arguments much as a function can. The syntax for
defining the macro is similar to that of a function. Here is an
example:
#define debug(format, ...) fprintf (stderr, format, __VA_ARGS__)
Here `...' is a "variable argument". In the invocation of such a
macro, it represents the zero or more tokens until the closing
parenthesis that ends the invocation, including any commas. This set of
tokens replaces the identifier `__VA_ARGS__' in the macro body wherever
it appears. See the CPP manual for more information.
GCC has long supported variadic macros, and used a different syntax
that allowed you to give a name to the variable arguments just like any
other argument. Here is an example:
#define debug(format, args...) fprintf (stderr, format, args)
This is in all ways equivalent to the ISO C example above, but arguably
more readable and descriptive.
....
相关阅读 更多 +