如何为几行代码禁用 GCC 警告 [英] How to disable GCC warnings for a few lines of code

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

问题描述

在 Visual C++ 中,可以使用 #pragma 警告(禁用: ...).我还发现在 GCC 中你可以 覆盖每个文件编译器标志.如何为下一行"或使用 GCC 的代码区域周围的推送/弹出语义执行此操作?

In Visual C++, it's possible to use #pragma warning (disable: ...). Also I found that in GCC you can override per file compiler flags. How can I do this for "next line", or with push/pop semantics around areas of code using GCC?

推荐答案

好像是这个可以做到.我无法确定它添加的 GCC 版本,但它是在 2010 年 6 月之前的某个时间.

It appears this can be done. I'm unable to determine the version of GCC that it was added, but it was sometime before June 2010.

这是一个例子:

#pragma GCC diagnostic error "-Wuninitialized"
    foo(a);         /* error is given for this one */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wuninitialized"
    foo(b);         /* no diagnostic for this one */
#pragma GCC diagnostic pop
    foo(c);         /* error is given for this one */
#pragma GCC diagnostic pop
    foo(d);         /* depends on command line options */

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

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