C++ pragma GCC system_header 指令

发布于 2024-08-06 16:45:20 字数 49 浏览 4 评论 0原文

这个 C++ 指令的作用是:“#pragma GCC system_header”?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一直在等你来 2024-08-13 16:45:20

我用谷歌搜索并得到这个

#pragma GCC system_header

此编译指示不带任何参数。它导致其余代码
当前文件被视为来自系统标头。第2.7节
系统标头。

有关系统标头的更多信息

2.7。系统标头

声明接口的头文件
到操作系统和运行时
库通常无法写入
严格符合C。因此,GCC
给出在系统头文件中找到的代码
特殊待遇。所有警告,其他
比 #warning 生成的那些
(第 5 章诊断)是
GCC 正在处理时被抑制
系统头。宏定义在
系统标头不受一些影响
无论它们在何处扩展,都会发出警告。
这种豁免权是临时授予的
基础上,当我们发现警告时
产生大量误报
因为宏中定义的代码
系统标头。

通常,只有在以下位置找到的标头
考虑特定目录
系统标头。这些目录是
GCC 编译时确定。那里
然而,有两种方法可以使正常
标头进入系统标头。

-isystem 命令行选项添加
它的参数列表
搜索标题的目录,
就像-I一样。在以下位置找到的任何标头
该目录将被考虑
系统标头。

所有由-isystem命名的目录都是
在所有名为的目录之后搜索
by -I,无论他们的顺序是什么
在命令行上。如果一样的话
目录由 -I 和 -I 命名
-isystem,-I 选项被忽略。 GCC 提供了一条信息丰富的消息
如果使用 -v,则会发生这种情况。

还有一个指令,#pragma GCC
system_header,它告诉 GCC
考虑当前的其余部分
包含文件系统头,否
不管它是在哪里发现的。编码
位于文件中#pragma 之前
不会受到影响。 #pragma GCC
system_header 没有影响
主要源文件。

在非常旧的系统上,一些
预定义的系统头目录
获得更加特殊的待遇。 GNU
C++ 考虑在以下位置找到的标头中的代码
那些目录被包围
外部“C”块。没有办法
请求此行为
#pragma,或从命令行。

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.

甜`诱少女 2024-08-13 16:45:20

它说,超过这一点的所有内容都被视为在系统标头中。这意味着除 #warning 之外的所有警告都将被抑制

It says that everything past this point is treated as if it were in a system header. That means that all warnings other than #warning are suppressed

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文