如何在几行代码中禁用g ++中的所有警告 [英] How to disable all warnings in g++ on a few lines of code

查看:293
本文介绍了如何在几行代码中禁用g ++中的所有警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在几行代码中禁用所有警告。
使用GCC诊断功能可以禁用特定警告,但是所有警告都有标志。
我试过这种方法,但它不起作用

pre $ g $ gcc诊断推送
#pragma GCC诊断忽略-wall
//一些代码
#pragma GCC诊断弹出窗口


解决方案

从这里开始: http:// dbp-consulting。 com / tutorials / SuppressingGCCWarnings.html



对于4.6或更高版本,您可以保存用户诊断标志的状态。您可以在导致虚假警告的行的周围插入:

  #pragma GCC诊断推送
#pragma GCC诊断忽略-Wdeprecated-declarations
//导致警告的代码在这里
#pragma GCC诊断弹出窗口

为了达到所需的行为,您应该使用-Wall而不是-Wdeprecated-declarations(而不是-wall - 注意大写W)。


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

解决方案

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").

这篇关于如何在几行代码中禁用g ++中的所有警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆