I spend a lot of time navigating and editing convoluted scientific C codes. Usually they contain hundreds of optional features switched on and off with preprocessor directives. This makes it almost impossible to say at a glance whether the current block of code is activated in my current setup or not. The code itself does not help as every feature is smudged all over the place and everything is usually done using global variables.
Is there an IDE that can handle preprocessor directives by folding/shading the inactive code?
I imagine one can maintain a project with a config of used flags and work with it not being bothered by inactive branches of logic.
Yes. Pass gcc the -E option. This will output preprocessed source code.
There are 4 Main Types of Preprocessor Directives: Macros. File Inclusion. Conditional Compilation. Other directives.
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:
unifdef
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With