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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With