So far, there are only two options (None, All), but I foresee another option Inner or something like that to mimic the behaviour of NamespaceIndentation.
The number of spaces between ‘#’ and the directive name is controlled by IndentWidth option (to be consistent with indentation inside namespaces, classes, blocks etc.), but it may be easily modified.
Two common styles I come across are whitespace indentation after the ‘#’ but before the pre-processing directive:
#if 0
define A
#endif
and whitespace indentation preceding the ‘#’ prefixed pre-processing directive:
#if 0
#define A
#endif
Can this rule handle both styles, or do you plan on supporting both styles? I’m not specifically in support of one style versus the other, but I strongly support the idea of a tool that can normalise styles to some given convention, and the more flexibility the better. And of course no indentation at all:
Is doing this even valid? I was under the impression that the C preprocessor required the hash to be on column 0. I’ve certainly had compilers reject code in the past where the preprocessor directives were indented accidentally.
I’ve had the same impression as David. But certainly, several modern compilers accept indented directives (clang, gcc, mscvc, icc).
Martin, may you be so kind and give some links to projects that use the space-before-hash style, please?
Anyway, it is pretty straightforward to add both styles. Do you have any ideas on naming? Should it be a single option (None, AllAfterHash, AllBeforeHash) or 2 options: one defining when to indent and the other - how to indent?
A good point, I’m not 100% sure if it is legal to precede the first ‘#’ with whitespace, though it seems to be commonly accepted. I’ll have to dig out my ANSI and ISO C documents.
I am not familiar with any Opensource project that uses this style, but I have seen it used in various companies I have done work for in the past; indeed, in one case it was part of their official coding practices. Interesting if it is not valid ISO C I’ve even seen examples such as: