Gcc preprocessor: can I only allow #if [def] s, leave the other directives intact?

I am doing some reverse engineering on some old code that is configured with a massive mix of #ifs and #ifdefs. I am currently reviewing various configurations, making replacements in the editor. This is both tedious and (I suspect) error prone.

Are there any gcc preprocessor options that will handle #if [def] s but leave the preprocessor directives (like #define) intact? This applies only to engineering purposes; I do not need to compile or otherwise use pre-processed code.

+4
source share
2 answers

I do not know any such function in the gcc preprocessor. And depending on what you are trying to do, it may even be impossible. If the #ifdef directive refers to a macro previously defined (or not) by the #define directive, and you ignore the #define directives, then this obviously does not work.

But the unifdef command is likely to be what you are looking for. I just installed it on my Ubuntu system using sudo apt-get install unifdef ; There should be similar installation methods on other systems.

+5
source

If you don't need to compile it, you can use the IDE's ability to understand ifdefs. In Eclipse, go to Project> Preferences> C / C ++ Build> Paths and Symbols and define the characters you need. Eclipse then ignores any ifdef whose characters are not defined.

+2
source

All Articles