C语言 编译C代码时如何禁用警告?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6882336/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 09:16:11  来源:igfitidea点击:

How to disable warnings when compiling C code?

cgcc

提问by Jeegar Patel

I am working on 32-bit Fedora 14 system. I'm compiling my source code using gcc.

我正在 32 位 Fedora 14 系统上工作。我正在使用gcc.

Does anybody know how to disable warnings while compiling c code?

有人知道如何在编译 c 代码时禁用警告吗?

回答by frx08

回答by Kracekumar

Every body tells use -Wallswitch with gcc, but you want to disable it. It is not advised, Use debugger to find it.

每个人都告诉使用-Wall带 gcc 的 switch,但你想禁用它。不建议,使用调试器查找。

Linus Torvalds:

莱纳斯·托瓦兹:

"But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

“但这显然是唯一正确的方法。其他人以其他方式这样做的事实仅意味着他们错了”

回答by DreiBaer

The best is to find the problem. It will prevent you in future looking for errors, which would not have occured, if you fixed the actual one.

最好是找到问题所在。如果您修复了实际的错误,它将防止您将来查找不会发生的错误。

But, if you're sure there is no bug or you have assured the problem is caught by your code, place this somewhere in the file (where 177 the number of your warning is):

但是,如果您确定没有错误或者您确定问题已被您的代码捕获,请将其放在文件中的某个位置(其中 177 是您的警告编号):

#pragma diag_suppress 177 // supress #177-D function  was declared but never referenced