gcc格式为哈希符号+数字“#1”的预处理输出行是什么意思?

Ben*_*enC 3 c++ gcc c-preprocessor

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

测试文件:test.cpp

#include <assert.h>

int main()
{
    int a = 1;
    assert (a >= 0);
    assert (a
            >= 0);
}
Run Code Online (Sandbox Code Playgroud)

命令

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__))
                 ;
Run Code Online (Sandbox Code Playgroud)

多行断言似乎被不同地处理,从而导致了这些# 7 "test.cpp" 3 4行。这到底是什么意思?

更新资料

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

MSa*_*ers 5

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

3 4 是标志,表示“从系统头开始的宏扩展”和 extern "C"

GCC文档