Difference between cpp and gcc -E

不想你离开。 提交于 2020-06-11 20:58:01

问题


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);

Result for 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;

$

Result for gcc -E and for 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 ?

Original code here


回答1:


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



来源:https://stackoverflow.com/questions/43967458/difference-between-cpp-and-gcc-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!