C IDE: preprocessing code navigation

Background

I spend a lot of time navigating and editing complicated scientific C codes. Usually they contain hundreds of additional functions turned on and off using preprocessor directives. This makes it almost impossible to immediately say whether the current code block is activated in my current setting or not. The code itself does not help, since every function is blurry everywhere, and everything is usually done using global variables.

Question

Is there an IDE that can handle preprocessor directives by folding / shading inactive code?

I assume that you can support the project with the configuration of the flags used and work with it without worrying about inactive branches of the logic.

+6
source share
3 answers

Looking at a similar question , it looks like the Eclipse CDT has the necessary functionality and another question actually says where you can install your ifdefs.

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

But you can also try to use the IDE-agnostic solution, for example, run the code through unifdef and work with the result. If you just need to read the code, this is an almost perfect solution. If you need to make some changes, things will get a little more complicated, but you can use git to manage the changes, for example:

  • import the entire code base into git
  • do unifdef
  • record the result to the base of your patches
  • work with the code base in any IDE / editor that you prefer, making changes as usual
  • if there is a need to create patches for the source code base, just check the original import commit and cherry pick (or rebase) your patches from your branch (of course, there is a chance of conflict, but this should be fairly easy to resolve, since you know your intent change for the code from the patch, and you just need to configure for ifdefs)
  • if there is a need to update the code base, just start with the original import, apply the update, commit it, execute through unifdef, commit it, and then update your changes on top of this

Of course, whether this approach works or not depends on the specific code base and what you are going to do with it, but it can be useful in some scenarios.

+7
source

I use Vim with several plugins as my IDE of choice (thanks Steve Francia ). Most likely, this is not your cup of tea, but just in case, I found a couple of suggestions for this.

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

C Fold preprocessor in Vim

+2
source

I have not heard of this feature in any IDE. BUT you can still use after processing the pre-processed code. Can gcc output C code after preprocessing?

+1
source

All Articles