c - 如何禁用几行代码的 GCC 警告

标签 c gcc compiler-warnings pragma

在 Visual C++ 中,可以使用 #pragma warning (disable: ...) .我还发现在 GCC 中你可以 override per file compiler flags .我如何为“下一行”或使用 GCC 在代码区域周围使用推送/弹出语义来执行此操作?

最佳答案

出现这个can be done .我无法确定它添加的 GCC 版本,但它是在 2010 年 6 月之前的某个时间。

这是一个例子:

#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 */

关于c - 如何禁用几行代码的 GCC 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3378560/

相关文章:

c - malloc 边界大小 : is there a performance difference

文字的 C float 赋值

c++ - 优化标志删除对外部变量的 undefined reference

c - 为什么我收到 "statement with no effect"警告?

c++ - 如何打开 icc/icpc 警告?

c - 在 C 中寻找调试功能

python - 如何在Python中获取C数组

c++ - 使用 boost locale 将 wchar_t 转换为 char

c - 将 GCC 选项添加到 C 源文件的顶部

haskell - 没有明确的实现警告