在 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/

10-13 08:06
查看更多