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