GCC,C:找出在#pragma ignore中使用的默认警告的名称 [英] GCC, C: Finding out name of default warnings for use in #pragma ignore

查看:711
本文介绍了GCC,C:找出在#pragma ignore中使用的默认警告的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解到,我可以将

I've learned that I can put

#pragma GCC diagnostic ignored "<warning>"

添加到源文件的顶部以抑制与此特定源文件相关的警告。但是,似乎有些名称不够具体。例如,

to the top of a source file in order to suppress warnings related to this particular source file. However, it seems that some names are not specific enough. For example,

#pragma GCC diagnostic ignored "-Wwrite-strings"

不会阻止gcc(4.7.2)显示未给出确切名称的警告消息,相反,这些消息仅在[缺省情况下启用] 。我想我需要知道正确的警告名称,以便我可以在 #pragma 行中使用它们。我已经尝试了

does not prevent gcc (4.7.2) from displaying warning messages whose exact names are not given, instead, these messages are followed only by [enabled by default]. I guess I need to know the correct warning names so I can use them in the #pragma line. I've tried

-fdiagnostics-show-option,

,但警告仍显示为[默认启用]。

but the warnings are then still displayed as [enabled by default].

有什么方法可以识别这些警告还是禁止与特定源文件相关的警告?

Is there any way to identiy these warnings or to alternatively suppress warnings related to a specific source file?

非常感谢!

Thank you very much!

推荐答案

您必须推送并弹出诊断状态。像这样:

You have to push and pop diagnostic states. Like this:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
    /* ignoring warning */

    int unused_function( void ) {
         return 1337;
    }
#pragma GCC diagnostic pop

这篇关于GCC,C:找出在#pragma ignore中使用的默认警告的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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