在为CUDA编译器进行错误报告时,我最终在gcc的预处理步骤中发现了这种奇怪的行为。我目前使用gcc 4.8.2。
#includeint main() { int a = 1; assert (a >= 0); assert (a >= 0); }
gcc -E -x c ++ -m64 -g -o“ test.cpp4.ii”“ test.cpp”
# 2 "test.cpp" 2 int main() { int a = 1; ((a >= 0) ? static_cast(0) : __assert_fail ("a >= 0", "test.cpp", 6, __PRETTY_FUNCTION__)); ((a >= 0) ? static_cast (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
预处理输入中的表示下一行的源是原始行中的line7(名为test.cpp)。
3 4
是标志,表示“从系统头开始的宏扩展”和 extern "C"
GCC文档