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

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

问题描述

在Visual C ++,它可以使用 #编译警告(禁用:...) 。此外,我发现,在海湾合作委员会可以override每个文件的编译器标志的。我怎样才能为下一行做到这一点,或推/左右使用GCC code领域流行的语义?

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?

推荐答案

看来这可以做到。我无法确定它加入海湾合作委员会的版本,但它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警告code几行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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