Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC preprocessor [duplicate]

Possible Duplicate:
Running the GCC preprocessor

Is there a GCC option to make the GCC preprocessor generate C source code but filter out irrelevant source code?

For example, a C file has #define switch to define for many different platforms. I'm only intersted in one platform, so I want the C preprocessor to filter out unrelated code. Does GCC support this?

like image 562
richard Avatar asked Oct 12 '10 17:10

richard


2 Answers

Use gcc -E to only run the preprocessor part, e.g. give a file in.c

#if 0
0;
#endif

#if 1
1;
#endif

running

$ gcc -E in.c -o in.i

yields a file in.i

# 1 "in.cpp"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "in.cpp"





1;

i.e. the parts behind the #if 0 got removed. If you would have #include'd files they would have been pasted too though, so I am not sure how much help this is.

like image 149
Benjamin Bannier Avatar answered Oct 17 '22 08:10

Benjamin Bannier


It sounds like you actually want unifdef, not the GCC preprocessor.

like image 42
Christoffer Avatar answered Oct 17 '22 08:10

Christoffer