【发布时间】:2015-02-05 12:04:10
【问题描述】:
我注意到这个程序是用 gcc 编译的:
#define X(A) A
int x = X(
#line 3 "test1.c"
0
);
然而,Visual Studio 编译失败:
main.cpp
main.cpp(6): error C2121: '#': invalid character: possibly the result of a macro expansion
main.cpp(6): error C2065: 'line': undeclared identifier
main.cpp(6): error C2143: syntax error: missing ';' before 'constant'
main.cpp(6): error C2059: syntax error: 'constant'
我想知道:该程序是否合法,或者它是否默默地依赖未定义(或实现定义)的行为而恰好使 gcc 接受代码?
【问题讨论】:
-
#line 在标准中,但可能是 Visual Studio 尝试将 "#line 3 \"test1.c\"\n0\n" 输入宏,而 GCC 评估 #在将其输入 X 之前的行
标签: c++ c visual-studio gcc