#pragma GCC system_header用法

在看公司公共庫的頭文件中發現了:#pragma GCC system_header一行,之前沒有見過這種用法,在網上查了一下,解釋以下:html

從#pragma GCC system_header直到文件結束之間的代碼會被編譯器視爲系統頭文件之中的代碼。系統頭文件中的代碼每每不能徹底遵循C標準, 因此頭文件之中的警告信息每每不顯示。(除非用 #warning顯式指明)。ide

能夠查看gcc參考手冊:http://gcc.gnu.org/onlinedocs/cpp/System-Headers.html#System-Headersspa

The header files declaring interfaces to the operating system and runtime libraries often cannot be written in strictly conforming C. Therefore, GCC gives code found in system headersspecial treatment. All warnings, other than those generated by ‘#warning’ (see Diagnostics), are suppressed while GCC is processing a system header. Macros defined in a system header are immune to a few warnings wherever they are expanded. This immunity is granted on an ad-hoc basis, when we find that a warning generates lots of false positives because of code in macros defined in system headers.rest

Normally, only the headers found in specific directories are considered system headers. These directories are determined when GCC is compiled. There are, however, two ways to make normal headers into system headers:code

  • Header files found in directories added to the search path with the -isystem and -idirafter command-line options are treated as system headers for the purposes of diagnostics.
  • There is also a directive, #pragma GCC system_header, which tells GCC to consider the rest of the current include file a system header, no matter where it was found. Code that comes before the ‘#pragma’ in the file is not affected. #pragma GCC system_header has no effect in the primary source file.
相關文章
相關標籤/搜索