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

时间:2013-11-28 15:51:09

标签: 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);
}

命令

  

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"(没有最后2个数字)。

1 个答案:

答案 0 :(得分:5)

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

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

GCC documentation