C ++编译指示GCC system_header指令 [英] C++ pragma GCC system_header directive

查看:706
本文介绍了C ++编译指示GCC system_header指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个C ++指令是做什么的:#pragma GCC system_header?

解决方案

我用Google搜索了


#pragma GCC system_header

 这个编译指示不需要任何参数。它会导致
当前文件中的其余代码被视为来自系统头文件。第2.7节
系统头。


关于系统头文件的更多信息


2.7。系统头文件

将操作系统和运行库
库中的接口
声明的头文件通常不能写入
严格符合C因此,GCC
给出系统头文件
中的代码特殊处理。所有的警告,其他
比#warning
(第5章诊断)生成的警告都是
,而GCC正在处理
系统标题。在
系统头文件中定义的宏无论在哪里展开,都可以免受一些
警告的影响。
当我们发现警告
由于在
系统中定义的宏中的代码而产生大量误报
时,这种豁免被授予特别的
基础头文件。


通常情况下,只有
特定目录中的头文件被认为是
系统头文件。这些目录是在编译GCC时确定的
。然而,
有两种方法可以将正常的
头文件制作成系统头文件。



-isystem命令行选项增加
其参数到
目录的列表以搜索标题,
就像-I一样。任何在
目录中找到的头文件将被认为是
系统头文件。


$ b 所有由-isystem命名的目录都是
,无论命令行上的命令是
,它都由-I命名为
。如果相同的
目录由-I和
-isystem命名,则-I选项将被忽略。如果使用-v,GCC会提供一条信息消息


还有一个指令#pragma GCC
system_header,它告诉GCC到
认为当前
的其余部分包含文件系统头文件,没有
在哪里找到它。代码
在文件
中的#pragma不会受到影响。 #pragma GCC
system_header在
主源文件中无效。



在很旧的系统中,定义的系统头文件目录
得到了更加特别的处理。 GNU
C ++考虑在
中找到的头文件中的代码,这些目录被
和一个externC块包围。使用
#pragma 或从命令行请求这种行为是没有办法的。

blockquote>

What this C++ directive do: "#pragma GCC system_header"?

解决方案

I googled and got this:

#pragma GCC system_header

This pragma takes no arguments. It causes the rest of the code in the
current file to be treated as if it came from a system header. Section 2.7
System Headers.

More info on System headers

2.7. 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 (Chapter 5 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.

The -isystem command line option adds its argument to the list of directories to search for headers, just like -I. Any headers found in that directory will be considered system headers.

All directories named by -isystem are searched after all directories named by -I, no matter what their order was on the command line. If the same directory is named by both -I and -isystem, the -I option is ignored. GCC provides an informative message when this occurs if -v is used.

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 will not be affected. #pragma GCC system_header has no effect in the primary source file.

On very old systems, some of the pre-defined system header directories get even more special treatment. GNU C++ considers code in headers found in those directories to be surrounded by an extern "C" block. There is no way to request this behavior with a #pragma, or from the command line.

这篇关于C ++编译指示GCC system_header指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆