Variadic宏是否是非标准的? [英] Are Variadic macros nonstandard?
问题描述
对于debugbuilds,我通常使用Clang,因为它更好地格式化警告和错误,并使它更容易跟踪和修复它们。
For debugbuilds, I usually use Clang, as it formats warnings and errors better, and makes it a little easier to track them down, and fix them.
但是最近在添加一个带有可变参数的宏之后,Clang告诉我以下(从一个虚拟项目):
But recently after adding a Macro with variadic arguments, Clang told me the following (from a dummy project):
main.cpp:5:20: warning: named variadic macros are a GNU extension [-Wvariadic-macros]
#define stuff3(args...) stuff_i(args)
我知道 macroname(args ...)
在大量编译器中编译良好,包括Visualstudio,Sunstudio ,当然还有GCC。但为了确保cl是正确的,我尝试了两种扩展可变参数的方法:
I know that macroname(args...)
compiles fine in a wide range of compilers, including Visualstudio, Sunstudio, and of course GCC. But just to make sure that clang is right, I tried two other ways of expanding the variadic arguments:
第1号:
#define stuff1(...) stuff_i(...)
b $ b
第2个:
Number 2:
#define stuff2(...) stuff_i(__VA_ARGS__)
我收到此信息:
main.cpp:3:16: warning: variadic macros were introduced in C99 [-Wvariadic-macros]
...这让我想知道Variadic宏是否是C ++标准的一部分(当然我知道Preprocessor是独立解释的)。
... Which makes me wonder if Variadic macros are actually part of the standard of C++ (and of course I know that the Preprocessor is interpreted independently)?
推荐答案
引用维基百科:
变量参数宏在1999年在C语言标准的ISO / IEC 9899:1999(C99)修订版中引入,2011年在ISO / IEC 14882:2011 ++ 11)C ++语言标准的修订版。
Variable-argument macros were introduced in 1999 in the ISO/IEC 9899:1999 (C99) revision of the C language standard, and in 2011 in ISO/IEC 14882:2011 (C++11) revision of the C++ language standard.
所以从C99和C ++ 11开始是标准的,在C ++ 03中。
So it's standard from C99 and C++11 onwards, but a GNU extension in C++03.
这篇关于Variadic宏是否是非标准的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!