-无墙 -Wreturn 型

发布于 2024-12-02 04:01:53 字数 1171 浏览 6 评论 0原文

根据 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼趣 2024-12-09 04:01:53

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

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

但是,这可能会导致您希望看到的其他警告被禁用。例如,它会抑制有关如下声明的变量的警告:

static x = 1;

选择你的毒药。

You can use -Wno-implicit-int to disable that warning:

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

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:

static x = 1;

Pick your poison.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文