简体   繁体   中英

gcc preprocessor: can I resolve #if[def]s only, leave other directives untouched?

I'm doing some reverse engineering on some old code that is configured by a massive tangle of #ifs and #ifdefs. I'm currently looking at the various configurations by doing the substitutions in an editor. This is both tedious and (I suspect) error-prone.

Are there some gcc preprocessor options that will preprocess the #if[def]s but leave other preprocessor directives (eg #define) untouched? This is for reverse engineering purposes only; I don't need to compile or otherwise use the preprocessed code.

I don't know of any such functionality in gcc's preprocessor. And depending on what you're trying to do, it might not even be possible. If a #ifdef directive refers to a macro previously defined (or not) by a #define directive, and you ignore #define directives, then that's clearly not going to work.

But the unifdef command is likely to be what you're looking for. I just installed it on my Ubuntu system with sudo apt-get install unifdef ; there should be similar ways to install it on other systems.

If you don't need to compile it, you can use the IDE's ability to understand ifdefs. In Eclipse, head to Project > Preferences > C/C++ Build > Paths and Symbols , and define the symbols you want. Eclipse will then ignore any ifdef whose symbols was not defined.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM