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?
C static code analysis: Preprocessor directives should not be indented.
Liberal blank lines and comments are the approach I've typically taken regarding non-indented #ifdef checks. All that said, there's no rule that you can't indent preprocessor checks if it makes the code more readable.
These commands specifies which sections of the code to compile or how to handle specific errors and warnings. C# preprocessor directive begins with a # (hash) symbol and all preprocessor directives last for one line. Preprocessor directives are terminated by new line rather than semicolon .
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
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