作为一个有洁癖的程序员,在编译c++ 项目的时候会去消灭每一个warning。在实际项目中,编译第三方库时候可能会不断产生warning信息,这种情况可以使用 diagnostic pragmas 限制选定的代码不产生warning信息。
假如我们想忽略某个c++ 源文件中所有-Wenum-compare 类型的warning信息。可以在头文件开始处加入以下
#pragma GCC diagnostic ignored "-Wenum-compare"
/**
* Code that generates this warning
*/
假如我们想忽略一个c++ 头文件中部分代码产生的warning 信息,我们可以使用push 和 pop 将那部分代码包起来,如下:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wenum-compare"
/**
* Code that generates this warning
*/
#pragma GCC diagnostic pop
消除C++警告
本文介绍如何使用GCC诊断指令来忽略特定类型的警告信息,包括在整个源文件或部分代码段中禁用-Wenum-compare警告。
269

被折叠的 条评论
为什么被折叠?



