【问题标题】:the format of the output of gcc preprocesinggcc 预处理输出的格式
【发布时间】:2021-03-04 14:52:01
【问题描述】:

我看到 gcc 预处理的以下输出。我没有找到输出格式的文档。谁能让我知道它是什么?谢谢。

$ cat a.h
#include "b.h"
$ cat b.h
#define X Y
$ gcc -E -dD - <<< '#include "a.h"'
...
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "<stdin>" 2
# 1 "./a.h" 1
# 1 "./b.h" 1
#define X Y
# 2 "./a.h" 2
# 2 "<stdin>" 2

当我尝试以下操作时,我看到了更多与上面不同的数字。我也不确定它们是什么意思。

$ gcc -E -dD - <<< '#include <sys/socket.h>'
...
# 19 "/usr/include/x86_64-linux-gnu/asm/posix_types_64.h" 2 3 4
# 8 "/usr/include/x86_64-linux-gnu/asm/posix_types.h" 2 3 4
# 37 "/usr/include/linux/posix_types.h" 2 3 4
# 6 "/usr/include/asm-generic/socket.h" 2 3 4
# 1 "/usr/include/x86_64-linux-gnu/asm/sockios.h" 1 3 4
# 1 "/usr/include/asm-generic/sockios.h" 1 3 4
...

【问题讨论】:

    标签: gcc clang c-preprocessor


    【解决方案1】:

    不寻常的行是行标记,它指定行号和文件名。文件名后面的数字是特殊标志。

    这些在GCC Preprocessor online documentation中解释:

    源文件名和行号信息由 表格

    # linenum filename flags

    这些被称为线标记。它们根据需要插入到 输出(但绝不在字符串或字符常量内)。他们的意思是 以下行源自文件 filename 的行 linenumfilename 永远不会包含任何非打印字符;他们是 替换为八进制转义序列。

    文件名后有零个或多个标志,分别是'1','2','3', 或“4”。如果有多个标志,则用空格分隔它们。这是 标志的含义:

    ‘1’表示新文件的开始。
    ‘2’ 这表示返回到一个文件(在包含另一个文件之后)。
    ‘3’ 这表示以下文本来自系统头文件,因此应禁止某些警告。
    ‘4’ 这表示以下文本应被视为包含在隐式 extern "C" 块中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-19
      • 1970-01-01
      • 1970-01-01
      • 2012-02-20
      • 2021-10-16
      • 2017-10-20
      • 2015-12-28
      • 2011-04-14
      相关资源
      最近更新 更多