简体   繁体   English

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

[英]How to disable warnings when compiling C code?

I am working on 32-bit Fedora 14 system.我正在开发 32 位 Fedora 14 系统。 I'm compiling my source code using gcc .我正在使用gcc编译我的源代码。

Does anybody know how to disable warnings while compiling c code?有人知道如何在编译 c 代码时禁用警告吗?


EDIT: Yes i know.编辑:是的,我知道。 Best thing is to fix those Warnings to avoid any undefined/unknown behavior.最好的办法是修复这些警告以避免任何未定义/未知的行为。 But currently here, i have written huge code first time and there are lots of error & warning in first compilation.但是目前在这里,我第一次编写了大量的代码,并且在第一次编译时有很多错误和警告。 Here i just want to concentrate on errors first and then i will see warnings.在这里,我只想先关注错误,然后我会看到警告。

Every body tells use -Wall switch with gcc, but you want to disable it.每个人都告诉使用 gcc 的-Wall开关,但你想禁用它。 It is not advised, Use debugger to find it.不建议使用调试器查找。

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" “但这显然是唯一正确的方法。其他人都以其他方式做这件事的事实只意味着他们错了”

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

假设您收到警告-Wfoo-bar尝试添加编译标志-Wno-foo-bar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM