GCC警告:ISO C不允许命名可变宏 [英] GCC warning: ISO C does not permit named variadic macros
问题描述
使用以下命令:
gcc -c -Wall -Wextra -pedantic -ansi -std = c99 -fstack-protector -all -fstack-check -O3 root.c -o rootTESTOBJECT
我得到编译器警告
root.h:76:22:warning:ISO C不允许命名可变宏
72 #ifdef调试
73 #include
74 #define crumb(phrase0 ...)printf(phrase0)
75 #else
76 #define crumb(phrase0 ...)
77 #endif
我相信选项
-ansi -std = c99
允许使用可变宏,它根据文档反正......
我试过编辑第76行到
76 #define crumb(phrase0 ...)printf()
看看这个固定的警告,但没有喜悦。
编译器verion是苹果的gcc,版本4.2.1
我不知道如果我需要太过于担心,但我真的不喜欢警告。
...
)一个名称( phrase0
)。 这是 GCC扩展。
C99 的确定义了一种将可变参数传递给宏的方法(参见§6.10.3/ 12和§6.10.3.1/ 2):变量参数是在定义的左侧(即 ...
)未命名
,并在右侧引用为 __VA_ARGS __
,如下所示:
#define crumb(...)printf(__ VA_ARGS__)
(顺便说一句,您的 gcc
参数不应该包括 -ansi
和 -std = c99
: -ansi
指定早期的C标准(不同地称为ANSI C,C89或C90);在这种情况下,两个选项的组合只会选择C99,因为 -std = c99
在 -ansi
在参数列表中,最后一个获胜。)
Using the following command
gcc -c -Wall -Wextra -pedantic -ansi -std=c99 -fstack-protector-all -fstack-check -O3 root.c -o rootTESTOBJECT
I get the compiler warning root.h:76:22: warning: ISO C does not permit named variadic macros
72 #ifdef Debug
73 #include <stdio.h>
74 #define crumb(phrase0...) printf(phrase0)
75 #else
76 #define crumb(phrase0...)
77 #endif
I believe the option -ansi -std=c99 allows the use of variadic macros, it does according to the docs anyway...
I have tried editing line 76 to
76 #define crumb(phrase0...) printf("")
to see if this fixed the warning but with no joy.
the compiler verion is Apple's gcc, version 4.2.1 I'm not sure if I need be too concerned by this but I really don't like warnings. What flag's am I missing ?
#define crumb(phrase0...) <whatever>
is giving a name (phrase0
) to the variable arguments (...
).
This is a GCC extension.
C99 does define a way of passing variable arguments to macros (see §6.10.3/12 and §6.10.3.1/2): the variable arguments are unnamed
on the left-hand side of the definitions (i.e. just ...
), and referenced on the right-hand side as __VA_ARGS__
, like this:
#define crumb(...) printf(__VA_ARGS__)
(By the way, your gcc
arguments should not include both -ansi
and -std=c99
: -ansi
specifies the earlier C standard (known variously as ANSI C, C89 or C90); the combination of both options only happens to select C99 in this case because -std=c99
appears after -ansi
in the argument list, and the last one wins.)
这篇关于GCC警告:ISO C不允许命名可变宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!