Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preprocessor directives indentation in Visual C++ 2010

Tags:

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?

like image 619
Laurent Couvidou Avatar asked Sep 04 '12 16:09

Laurent Couvidou


People also ask

Should preprocessor directives be indented?

C static code analysis: Preprocessor directives should not be indented.

Can Ifdef 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.

Where are preprocessor directives defined in C#?

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 .


1 Answers

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 
like image 98
Nicola Musatti Avatar answered Oct 04 '22 00:10

Nicola Musatti