如何在Visual C ++中禁止显示外部标头中的警告 [英] How to suppress warnings in external headers in Visual C++

查看:126
本文介绍了如何在Visual C ++中禁止显示外部标头中的警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开始一个新的BREW项目,并且我希望使用警告级别4(/W4)进行编译,以保持应用程序代码的美观和整洁.问题在于BREW标头本身无法使用/W4干净地编译.

I'm starting a new BREW project, and I'd like to compile with Warning Level 4 (/W4) to keep the application code nice and clean. The problem is that the BREW headers themselves don't compile cleanly with /W4.

在gcc中,您可以使用-I和-isystem来区分应用程序标头和系统标头,然后默认情况下,gcc不会在系统标头中报告任何编译警告.在Visual C ++中有等效的机制吗?

In gcc you can differentiate between application and system headers by using -I and -isystem, and then by default gcc doesn't report any compilation warnings in system headers. Is there an equivalent mechanism in Visual C++?

推荐答案

仅在无法更改但需要包括的标头块周围使用此方法.

Only use this method around a block of headers that you cannot change, but that you need to include.

您可以有选择地暂时禁用所有警告,例如:

You can selectively, and temporarily disable all warnings like this:

#pragma warning(push, 0)        
//Some includes with unfixable warnings
#pragma warning(pop)

您可以选择传入警告编号来禁用它,而不是0,例如:

Instead of 0 you can optionally pass in the warning number to disable, so something like:

#pragma warning( push )
#pragma warning( disable : 4081)
#pragma warning( disable : 4706 )
// Some code
#pragma warning( pop ) 

这篇关于如何在Visual C ++中禁止显示外部标头中的警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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