tags:

views:

41

answers:

3
+1  Q: 

gcc preprocessor

is there a option that gcc preprocessor could generate C source code and filt out un-relavented source code. for example. a c file has #define switch to define for many diffenrent platforms. I'm only intersted in one platform, I want c preprocessor to filt out un-related code. Could GCC support this?

Thanks for help

Richard Luo

A: 

Yes. Use the -E option:

gcc -E foo.c
JesperE
+1  A: 

While the -E option will perform all pre-processing, it also produces some very 'raw' output that might not be what you want (depending on what you want).

If you need to debug a macro expansion that's not doing what you expect, E is a good way to go. If you simply want to filter out the 'inactive code', but leave the remaining code in more-or-less original form, you might want to look at the answers to the following stackoverflow question:

Michael Burr
A: 

I answered in the duplicated question, so I guess I'll duplicate the answer as well: It sounds like you want unifdef not the GCC preprocessor.

Christoffer