Search code examples
c++c-preprocessorindentationvisual-c++-2010preprocessor-directive

Preprocessor directives indentation in Visual C++ 2010


I often find myself in situations where I would like to indent preprocessor directives like the rest of the code (e.g. #if indented like if). It seems legal, it's common sense that it's sometimes a good thing, but Visual won't make it easy.

Is there a way to prevent the Visual C++ 2010 editor from sticking the code to the left each time I innocently press #? And to not break preprocessor directives indentation with auto-indent (CTRL+K, CTRL+F)? Or even better, to handle preprocessor directives like everything else?


Solution

  • My approach is to keep the # in the first column and indent the subsequent word, as in:

    #ifdef FIRST
    #  include "first.h"
    #else
    #  include "second.h"
    #endif