How to disable all warnings in g++ on a few lines of code

久未见 提交于 2019-12-21 05:06:21

问题


How to disable all warnings on a few lines of code. Specific warnings can be disabled using GCC diagnostic feature, but is there a flag for all warnings. I tried this way but it doesn't work

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-wall"
// some code
#pragma GCC diagnostic pop

回答1:


From here: http://dbp-consulting.com/tutorials/SuppressingGCCWarnings.html

For version 4.6 or later, you can save the state of the user's diagnostic flags. You can insert this around the line that causes the spurious warning:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
    // Code that causes warning goes here
#pragma GCC diagnostic pop

In order to achieve the desired behavior, you should use "-Wall" instead of "-Wdeprecated-declarations" (and not "-wall" -- note the upcase "W").




回答2:


I think gcc -w filename.c does so
-w flag is to ignore warnings



来源:https://stackoverflow.com/questions/6407298/how-to-disable-all-warnings-in-g-on-a-few-lines-of-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!