-无墙 -Wreturn 型
根据 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’
Is it possible to use -Wall
butdisable -Wreturn-type
Complete ?或者也许我错过了另一个可用的选项?
如果重要的话,我使用的是 Mac OS 10.7 (Darwin 11) 和 GCC 4.2.1(奇怪的是,使用 LLVM 编译:P)
According to the GCC manual, the -Wreturn-type
options is enabled with -Wall
. However, I can't find a proper way to disable it while keeping the rest of -Wall
enabled.
Consider this code:
func() {}
If compiled without warnings, no output is produced. Now, if I turn on -Wall
the following lines will appear:
$ 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
Ok, all nice. Now, if compiled with -Wreturn-type
, the same output is produced:
$ 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
So, I conclude that -Wreturn-type
is responsible for those warnings. But maybe it's not, or I'm doing something worse, as this was expected to produce no output:
$ gcc fn.c -Wall -Wno-return-type
fn.c:1: warning: return type defaults to ‘int’
Is it possible to use -Wall
but disable -Wreturn-type
completely? Or maybe I'm missing another available option?
If it matters, I'm on Mac OS 10.7 (Darwin 11) with GCC 4.2.1 (strangely enough, compiled with LLVM :P)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 -Wno-implicit-int 禁用该警告:
但是,这可能会导致您希望看到的其他警告被禁用。例如,它会抑制有关如下声明的变量的警告:
选择你的毒药。
You can use
-Wno-implicit-int
to disable that warning:However, this might cause other warnings that you might want to see to be disabled. For example, it'll suppress warning about a variable declared like so:
Pick your poison.