-Wall without -Wreturn-type

时间:2011-08-29 23:35:35

标签: c gcc gcc-warning

根据GCC手册,-Wreturn-type选项已启用-Wall。但是,我无法找到一种正确的方法来禁用它,同时保持-Wall的其余部分已启用。

考虑以下代码:

func() {}

如果在没有警告的情况下编译,则不会生成输出。现在,如果我打开-Wall,则会显示以下行:

$ gcc fn.c -Wall
fn.c:1: warning: return type defaults to ‘int’
fn.c: In function ‘func’:
fn.c:1: warning: control reaches end of non-void function

好的,一切都很好。现在,如果使用-Wreturn-type进行编译,则会生成相同的输出:

$ gcc fn.c -Wreturn-type
fn.c:1: warning: return type defaults to ‘int’
fn.c: In function ‘func’:
fn.c:1: warning: control reaches end of non-void function

因此,我得出结论,-Wreturn-type负责这些警告。但也许不是,或者我做的更糟糕,因为预计不会产生任何输出:

$ gcc fn.c -Wall -Wno-return-type
fn.c:1: warning: return type defaults to ‘int’

是否可以使用-Wall但完全禁用-Wreturn-type?或者也许我错过了另一个可用选项?

如果重要的话,我使用的是GCC 4.2.1的Mac OS 10.7(Darwin 11)(奇怪的是,用LLVM编译:P)

1 个答案:

答案 0 :(得分:7)

您可以使用-Wno-implicit-int禁用该警告:

gcc -c -Wall -Wno-return-type -Wno-implicit-int fn.c

但是,这可能会导致您可能希望禁用其他警告。例如,它将禁止对如此声明的变量发出警告:

static x = 1;

选择你的毒药。

相关问题