拼接物理源线以形成逻辑源线:编译器产生不同的输出
示例代码(t6.c
):
xxx \
#error
Incocations&输出:
# on Windows
$ gcc -c -std=c11 -pedantic -Wall -Wextra -E t6.c
xxx
#error
# on Windows
$ clang -c -std=c11 -pedantic -Wall -Wextra -E t6.c
xxx #error
# on Windows
$ cl /std:c11 /E t6.c
xxx \
t6.c(2): fatal error C1189: #error:
# on Linux
$ icc -c -std=c11 -pedantic -Wall -Wextra -E t6.c
xxx #error
如何解释差异?
在我的理解中:
- clang和icc是可以的,
- MSVC不剪接物理源线以形成逻辑源线
- gcc可能会拼接(因此它找不到
#Error
),而是逻辑源线( IEXXX #ERROR
未形成
Sample code (t6.c
):
xxx \
#error
Invocations & output:
# on Windows
$ gcc -c -std=c11 -pedantic -Wall -Wextra -E t6.c
xxx
#error
# on Windows
$ clang -c -std=c11 -pedantic -Wall -Wextra -E t6.c
xxx #error
# on Windows
$ cl /std:c11 /E t6.c
xxx \
t6.c(2): fatal error C1189: #error:
# on Linux
$ icc -c -std=c11 -pedantic -Wall -Wextra -E t6.c
xxx #error
How the differences can be explained?
In my understanding:
- Clang and ICC are OK
- MSVC does not splice physical source lines to form logical source lines
- GCC may splice (so it does not find
#error
as MSVC does), but the logical source line (i.e.xxx #error
) is not formed
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论