When there are many preprocessor statements and many #ifdef cascades, it's hard to get an overview since normally they are not indented. e.g.
#ifdef __WIN32__ #include <pansen_win32> #else #include <..> #ifdef SOMEOTHER stmts #endif maybe stmts #endif
When I consider also indenting those preprocessor statements, I fear of getting confused with the general indentation level. So how do you solve this in a beautiful way?
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.
Preprocessor statements are handled by the compiler (or preprocessor) before the program is actually compiled. All # statements are processed first, and the symbols (like TRUE) which occur in the C program are replaced by their value (like 1).
All Preprocessor directives begin with the # (hash) symbol. C++ compilers use the same C preprocessor. The preprocessor is a part of the compiler which performs preliminary operations (conditionally compiling code, including files etc...) to your code before the compiler sees it.
Just because preprocessing directives are "normally" not indented is not a good reason not to indent them:
#ifdef __WIN32__ #include <pansen_win32> #else #include <..> #ifdef SOMEOTHER stmts #endif maybe stmts #endif
If you frequently have multiple levels of nesting of preprocessing directives, you should rework them to make them simpler.
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