Preprocessor-aware code navigation in IDE for C project

一曲冷凌霜 提交于 2019-12-04 04:26:24
Roman Khimov

Looking at similar question it seems like Eclipse CDT has exactly the functionality you need and the other question actually tells where you can set your ifdefs.

Emacs has something similar in form of hide-ifdef-mode.

But you can also try to use IDE-agnostic solution like running the code through unifdef and working with the result. If you just need to read the code, it's almost perfect solution. If you need to make some changes, things become a bit more complicated, but you can use git then to manage changes, like:

  • import whole code base into git
  • run through unifdef
  • commit the result, that's the basis for your patches
  • work with the code base in whatever IDE/editor you prefer, commiting changes as usual
  • if there is a need to produce patches for original code base, just checkout the original import commit and cherry-pick (or rebase) your patches from your branch (of course there is a chance for conflict, but it should be quite easy to resolve as you know your intended change for the code from the patch and you just need to adjust for ifdefs)
  • if there is a need to update code base, just start from original import, apply an update, commit that, run through unifdef, commit that and then rebase your changes on top of that

Of course, whether this approach will work or not depends on particular code base and what you're going to do with it, but it can be useful in some scenarios.

Jeremy Thien

I use Vim with several plugins as my IDE of choice (thank you Steve Francia). It is likely this is not your cup of tea, but in case it is, I found a couple suggestions to accomplish this.

Autofold #ifdef..#endif in Vim via .vimrc

C Preprocessor Fold in Vim

Alex Baranowski

I haven't heard about this feature in any IDE. BUT you can still use after preprocessed code to work with. Can gcc output C code after preprocessing?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!