3

I am trying to navigate a C project that has lots of preprocessor directives like this:

#ifdef SOME_COMPILE_TIME_VARIABLE
    for ( idx=0; idx<FOO; idx++ ) {
#else
    for ( idx=0; idx<BAR; idx++) {
#endif        
        var[idx] += data[idx];
    }

Unfortunately, this seems to break many editor features. By far the worst symptom is that indentation becomes broken from that point all the way to the bottom of the buffer because there seems to be an unmatched open brace. Other features that break include code folding and semantic navigation (e.g. c-end-of-defun)

I can imagine some ways of working around this problem by editing the code itself. Like this for example:

#ifdef SOME_COMPILE_TIME_VARIABLE
    for ( idx=0; idx<FOO; idx++ )
#else
    for ( idx=0; idx<BAR; idx++)
#endif
    {
        var[idx] += data[idx];
    }

But since the code does not belong to me, I do not have the option of editing the entire code base so that it plays nicely with my editor. And in many cases, this would not be practical even it were permissible.

Is there a way to mitigate the negative effects of mismatched parentheses and braces like this, which are due to precompiler directives?

  • what you seeing is not the 'negative effect of mismatched braces ...' but rather the 'negative effects of placing the opening brace '{' after the statement rather than on a separate line. – user3629249 Jun 9 '16 at 15:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.