[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: preprocessor directive indentation, cppi
From: |
Bruce Korb |
Subject: |
Re: preprocessor directive indentation, cppi |
Date: |
Sun, 20 Feb 2011 18:05:24 -0800 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.16) Gecko/20101125 SUSE/3.0.11 Thunderbird/3.0.11 |
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".
- [PATCH] test-exclude.c: remove unmatched #endif, Jim Meyering, 2011/02/20
- Re: [PATCH] test-exclude.c: remove unmatched #endif, Bruno Haible, 2011/02/20
- Re: [PATCH] test-exclude.c: remove unmatched #endif, Jim Meyering, 2011/02/20
- Re: preprocessor directive indentation, cppi, Bruno Haible, 2011/02/20
- Re: preprocessor directive indentation, cppi,
Bruce Korb <=
- Re: preprocessor directive indentation, cppi, Jim Meyering, 2011/02/21
- Re: preprocessor directive indentation, Bruno Haible, 2011/02/20