根据 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
?或者也许我错过了另一个可用的选项?
如果重要的话,我在 Mac OS 10.7(Darwin 11)和 GCC 4.2.1 上(奇怪的是,用 LLVM 编译:P)