David said:
Bogdan wrote:
Can anyone recommend a program for indentation of C preprocessor
directives. My file looks like this:
#ifdef a
#define b
#else
#define c
#endif
[...]
and I want a program able to automatically indent the preprocessor
directives.
[...]
If what you want is something similar to this
#ifdef a
#define b
#else
#define c
#endif
, then I think you've got quite an unusual habit...
Maybe unusual, but at least *I* don't feel so lonely anymore ;-)
I think some compilers long ago didn't support preprocessor
directives with the # other than in the first column, but none I've
used in that past few years have that restriction.
I've seen programs keep the '#' in the first column, and insert
whitespace between it and the directive. (Does the Standard say
that this is allowed?) Using the same example:
#ifdef a
# define b
#else
# define c
#endif
Seriously, isn't the indented clause version *way* easier to read?
If we indent if clauses, why shouldn't we indent #if clauses for the
same reason?
When you have complex nested #if/#ifdef's, it is certainly easier
to read for me. However, I've been programming long enough that I've
used compilers that required the '#' in column 1, and no whitespace
following it, so I got in the habit of not indenting such things.
If the Standard guarantees both/either of the above, I just may
retrain myself.