8

Visual Studio 2012 と次の簡単なプログラムで、警告レベルを EnableAllWarnings (/Wall) に設定しました。

#include "math.h"

int main() {
    return 0;
}

コンパイルすると、次のようないくつかの警告が表示されました。

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

これらの警告を削除する方法を知っている人はいますか?

4

2 に答える 2

8

Look carefully at the warning messages you're actually getting:

1> warning C4514: 'hypot' : unreferenced inline function has been removed

If you are saying to yourself "so?!", then that's exactly my point.

Warning C4514 is a notoriously useless one and is literally just crying out to be suppressed globally. It is a completely non-actionable item and describes an expected case when you're working with a library.

Warning C4711—a function has been selected for inline expansion—is another noisy warning you'll see. Of course, you'll only get this one when compiling with optimizations enabled, which is probably why you haven't seen it yet.

Like the linked documentation says, these are "informational warnings" and they're disabled by default. Which is great, except that I, like you, prefer to compile my code with "All Warnings" (/Wall) enabled, and these just add noise. So I turn them back off individually.

You can disable these warnings either by adding the suppressions to your project's properties in the VS IDE, or you can use pragma directives at the top of your code file (e.g., in your precompiled header):

#pragma warning(disable: 4514 4711)
于 2013-03-29T23:24:02.947 に答える
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)

コードを MS 以外の環境に移植する予定がある場合は、移植時に変更できるように、使用されているすべての外部ヘッダーを特定のヘッダーにラップすることをお勧めします。

于 2013-03-29T22:48:21.347 に答える