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