g++ -E选项输出的含义是什么?

6

使用此选项,我在预处理后接收文件。有很多类似以下的行:

# 91 "/usr/include/stdint.h" 3 4

这些数字代表什么意思?一开始我以为#91是文件包含的行号,但事实并非如此。至于3 4,我完全不知道它表示什么。
3个回答

8

根据官方文档,该行的格式为:

# linenum filename flags

linenum参数指定了下一行代码的来源位置,即在filename文件中的行数。然后有四个标志:

  • 1 - 新文件的开头
  • 2 - 返回到文件中
  • 3 - 系统头文件
  • 4 - 将其视为被包含在extern "C"

因此,让我们解释一下您的line marker:

# 91 "/usr/include/stdint.h" 3 4

以下行来自于 /usr/include/stdint.h 的第 91 行。它是一个系统头文件,应该被视为包含在 extern "C" 中。

6
这些被称为“行标记”。根据文档的说明:

Source file name and line number information is conveyed by lines of the form

# linenum filename flags

These are called linemarkers. They are inserted as needed into the output (but never within a string or character constant). They mean that the following line originated in file filename at line linenum. filename will never contain any non-printing characters; they are replaced with octal escape sequences.

After the file name comes zero or more flags, which are ‘1’, ‘2’, ‘3’, or ‘4’. If there are multiple flags, spaces separate them. Here is what the flags mean:

  • ‘1’ - This indicates the start of a new file.
  • ‘2’ - This indicates returning to a file (after having included another file).
  • ‘3’ - This indicates that the following text comes from a system header file, so certain warnings should be suppressed.
  • ‘4’ - This indicates that the following text should be treated as being wrapped in an implicit extern "C" block.

1

这里有一些标志(用空格隔开),它们的含义如下:

1 - Start of a new file
2 - Returning to previous file
3 - Following text comes from a system header file (#include <> vs #include "")
4 - Following text should be treated as being wrapped in an implicit extern "C" block.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接