0

I have a large code I want to go over and it has a lot of parts "macroed out":

#define DEBUG 0
#if DEBUG
...
#endif

The (...) is mostly debug printf's. Is there a way to remove all these code lines that eventually won't execute?

CIsForCookies
  • 12,097
  • 11
  • 59
  • 124
  • By using preprocessor of your C compiler or by writing a small utility to do so and using it? – MikeCAT Jul 31 '16 at 08:26
  • @MikeCAT I guess I could write a python script to fix my code, but is there a built-in tool for that? – CIsForCookies Jul 31 '16 at 08:28
  • 1
    I suggest commenting out all includes (so as not to expand them) and then asking your compiler for preprocessor-output. Look in the manual for the proper option. There might be a problem with all the #define's and #undefine's being stripped out, if they were meant to influence the included contents though, or later conditionals defend on macros defined in them. – Deduplicator Jul 31 '16 at 08:30
  • I know this is a comment which does'n answer your question: I wouldn't call this "macroed out". You may need the _debug prints_ already in the next step of your development cycle. – user3078414 Jul 31 '16 at 08:34
  • 1
    @user3078414 the debug prints are very needed, but not when I want to read the base code in order to understand it... – CIsForCookies Jul 31 '16 at 08:35
  • 1
    Taking a look at [this SO post](http://stackoverflow.com/questions/22738929/tool-to-remove-apply-ifdefs-elses-from-codebase) may help. – user3078414 Jul 31 '16 at 08:39
  • There's a partial C preprocessor https://github.com/BR903/cppp It only works with `#iffdef`, not `#if` but this is solvable with a bit of `sed`. – n. m. could be an AI Jul 31 '16 at 08:53
  • I think it is best to go through them one by one - to prevent you having unintended consequences – Ed Heal Jul 31 '16 at 10:49
  • Can you use a folding editor for reading? Many editors off little "[-]" on the left window border, clicking it will hide typical code constructs and leave a "[+]", to be clicked for unhiding the code part. – Yunnosch Apr 09 '17 at 11:34

0 Answers0