On 02/20/11 16:58, Bruno Haible wrote: >> it lets you distinguish conditional and unconditional >> #include directives and #define directives based solely >> on presence or absence of spaces after the "#". > > This heuristic does not always work: > - sleep.c:# define WIN32_LEAN_AND_MEAN > is semantically an unconditional define (it is defined on all platforms > where it matters), like in accept.c. > - tsearch.c:#define CHECK_TREE(a) check_tree(a) > is a conditional definition. This code comes from glibc. > > So in practice, I have to grep for "# *define" anyway.
OK, I've got a couple of pennies for this, too: if you want a CPP directive indentation validator, it should constrain itself to validating that all directives at a particular nesting level are at the same indentation level and that that level is not less than its containing level. e.g., if there is only one nesting level in a header, it is likely the double inclusion guard and everything ought to be hunky-dory with no indentation. *However*, if someone chooses to indent something with a space between the hash and directive, then everything at that level and deeper must be indented by that much and only more if it is nested deeper, too. I think that's the lowest common denominator and doesn't impose anything that neither Bruno nor I would dislike. These would be "okay" (indentation always >= containing "#if"): > #if > # include > # if > # define > # endif > #endif > > #if > # include > #endif > #if > #include > #endif This would violate "not less at same level": > #if > # include > #else > #include > #endif because, basically, both "includes" are in the same construct, though not the same section of the "#if".