Share via


system_header pragma

將檔案的其餘部分視為診斷報告的外部。

語法

#pragma system_header

備註

system_headerpragma 會指示編譯器在目前原始程式檔其餘部分的 選項所 /external:Wn 指定的層級顯示診斷。 如需如何指定外部檔案和編譯器外部警告層級的詳細資訊,請參閱 /external

system_headerpragma 不會套用到目前原始程式檔結尾。 換句話說,它不適用於包含此檔案的檔案。 system_headerpragma 即使沒有其他檔案指定為編譯器外部,也會套用 。 不過,如果未 /external:Wn 指定任何選項層級,編譯器可能會發出診斷,並使用它套用至非外部檔案的相同 警告層級 。 影響警告行為的其他 pragma 指示詞仍會套用在 之後 system_headerpragma 。 的效果 #pragma system_header 類似 warning pragma

// If n represents the warning level specified by /external:Wn,
// #pragma system_header is roughly equivalent to:
#pragma warning( push, n )

// . . .

// At the end of the file:
#pragma warning( pop )

system_headerpragma 從 Visual Studio 2019 16.10 版開始提供 。

範例

此範例標頭示範如何將檔案的內容標示為外部:

// library.h
// Use /external:Wn to set the compiler diagnostics level for this file's contents

#pragma once
#ifndef _LIBRARY_H // include guard for 3rd party interop
#define _LIBRARY_H
#pragma system_header
// The compiler applies the /external:Wn diagnostic level from here to the end of this file.

// . . .

// You can still override the external diagnostic level for warnings locally:
#pragma warning( push )
#pragma warning( error : 4164 )

// . . .

#pragma warning(pop)

// . . .

#endif

另請參閱

/external
warning pragma
/Wn (編譯器警告層級)
Pragma 指示詞和 __pragma_Pragma 關鍵字