gcc 预处理的表单哈希符号 + 数字"# 1"输出行是什么意思?

What do gcc preprocessed output lines of form hash sign + digit "# 1" mean?

本文关键字:输出 是什么 意思 数字 预处理 表单 哈希 符号 gcc      更新时间:2023-10-16

在为CUDA的编译器做错误报告时,我在gcc的预处理步骤中发现了这种奇怪的行为。我目前使用的是gcc 4.8.2。

测试文件:Test.cpp

#include <assert.h>
int main()
{
    int a = 1;
    assert (a >= 0);
    assert (a
            >= 0);
}

命令

gcc-E-x c++-m64-g-o"test.cpp4.ii"test.cpp"

结果文件:test.cpp4.ii

# 2 "test.cpp" 2
int main()
{
    int a = 1;
    ((a >= 0) ? static_cast<void> (0) : __assert_fail ("a >= 0", "test.cpp", 6, __PRETTY_FUNCTION__));
    ((a >= 0) ? static_cast<void> (0) : __assert_fail ("a >= 0",
 "test.cpp"
# 7 "test.cpp" 3 4
    ,
 8
# 7 "test.cpp" 3 4
    , __PRETTY_FUNCTION__))
                 ;

多行断言的处理方式似乎有所不同,从而产生了这些# 7 "test.cpp" 3 4行。这到底是什么意思?

更新

显然,gcc 4.7给出了# 7 "test.cpp"(没有最后两个数字)。

它看起来像线条标记。正如您可能已经注意到的,原始文件和预处理文件中的行号之间没有微不足道的关系。预处理输入中的# 7表示下一行的来源是原始文件中的第7行(名为test.cpp)

3 4是标志,表示"从系统头进行宏扩展"和extern "C"

GCC文档