问题
I know it is a very stupid question but I cannot get the difference between system header and normal header in gcc.
Refering to this link:
2.8 System Headers
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 headers special 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.
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:
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.
I appreciate an answer showing some contents of system header if possible and what kind of warnings or special treatment is talking about in the link.
回答1:
System headers are header files that come with the OS or compiler, and are located in directories like /usr/include
on Unix. Normal headers are everything else, such as the header files you write yourself, or files that come with an application or library you download.
回答2:
what kind of warnings or special treatment is talking about in the link.
These are warnings that are issued for C usage that is deprecated under current standards but was considered acceptable when the system headers were written. For example, the warning you are assigning a string literal to a char*"
. (which nowadays would be done using the const
keyword).
来源:https://stackoverflow.com/questions/41685746/system-header-and-normal-header-gcc