cpp和gcc -E之间的区别 [英] Difference between cpp and gcc -E
本文介绍了cpp和gcc -E之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我认为 cpp foo.c
和 gcc -E foo.c
都可以对源文件进行预处理
I thought that both cpp foo.c
and gcc -E foo.c
do preprocess the source file the same way, but I got their output to differ for the same file.
$ cat foo.c
#define VARIABLE 3
#define PASTER(x,y) x ## _ ## y
#define EVALUATOR(x,y) PASTER(x,y)
#define NAME(fun) EVALUATOR(fun, VARIABLE)
extern void NAME(mine);
cpp
的结果:
$ cpp foo.c
# 1 "foo.c"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 329 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "foo.c" 2
extern void mine ## _ ## 3;
$
gcc -E
和 clang -E
:
$ gcc -E foo.c
# 1 "foo.c"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 330 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "foo.c" 2
extern void mine_3;
$
为什么这些输出会有所不同,以及当我想要使用哪个输出时请参阅预处理的源代码?
Why do those outputs differ, and which one should I use when I want to see the preprocessed source ?
原始代码此处
推荐答案
两者之间的区别在于 gcc -E
将消除 -traditional-cpp
。如果包含该选项,则应该收到与 cpp
相同的结果。
The difference between the two is that gcc -E
will eliminate -traditional-cpp
. If you include the option then you should receive the same result as cpp
.
↳ https://gcc.gnu.org/onlinedocs/cpp/Traditional-Mode.html
这篇关于cpp和gcc -E之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文