如何禁止内部Visual Studio文件的警告

Dan*_*tti 6 c++ compiler-warnings visual-c++ visual-studio-2012

我在Visual Studio 2012和这个简单的程序中将警告级别设置为EnableAllWarnings(/ Wall):

#include "math.h"

int main() {
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

当我编译时,我收到了几个警告:

1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\math.h(161): warning C4514: 'hypot' : unreferenced inline function has been removed

如果我更换"math.h""string.h"我继续接收有关的警告string.h等.

有谁知道如何删除这些警告?

ble*_*sio 7

也许这会成功:

// you can replace 3 with even lower warning level if needed 
#pragma warning(push, 3) 

#include <Windows.h>
#include <crtdbg.h>
#include "math.h"
//include all the headers who's warnings you do not want to see here

#pragma warning(pop)
Run Code Online (Sandbox Code Playgroud)

如果您计划将代码移植到非MS环境,那么您可能希望将所有使用过的外部标头包装在特定的标头中,以便在移植时可以更改它.


Cod*_*ray 6

仔细查看您实际获得的警告消息:

1> warning C4514: 'hypot' : unreferenced inline function has been removed
Run Code Online (Sandbox Code Playgroud)

如果你对自己说"那么?!" 那么这正是我的观点.

警告C4514是一个臭名昭着的无用的,实际上只是急于被全球压制.这是一个完全不可操作的项目,描述了当您使用库时的预期情况.

警告C4711 - 已选择内联扩展功能 - 这是您将看到的另一个噪音警告.当然,在启用优化的情况下进行编译时,你只会得到这个,这可能就是为什么你还没有看到它.

与链接文档一样,这些是"信息警告",默认情况下它们被禁用.这很棒,除了我和你一样,我更喜欢在/Wall启用"All Warnings"()的情况下编译我的代码,这些只是添加噪音.所以我将它们单独关闭.

您可以通过在VS IDE中向项目属性添加抑制来禁用这些警告,也可以在代码文件的顶部使用pragma指令(例如,在预编译的头文件中):

#pragma warning(disable: 4514 4711)
Run Code Online (Sandbox Code Playgroud)