Re: Clarifying confusion of our variable placement rules caused by cleanup.h

From: H. Peter Anvin

Date: Tue Nov 18 2025 - 14:24:05 EST


On 2025-11-18 08:39, James Bottomley wrote:
>
> For myself I do find some value in the C89 declarations at the
> beginning of the block for readability, so I'm happy to relax the
> mixing rule to cases where it's strictly necessary and require
> documenting in the comment what the necessity is. However, I do think
> we should, absent ordering problems, keep __free variables
> uninitialised and at the top of the block given we can detect any
> problem (and thus keep this rule absolutely for non-__free variables
> where there's no ordering issues). But, again, I'm less attached to
> this position than I am to the consistency one: I really think it's a
> bad idea to change the rules for one class of variables but not for
> another, so whatever we do, we should do it for everything and if that
> means relaxing the rule mixing code and declarations for everthing, I
> can live with that.
>

To me, a major win with pushing declarations down to first initialization or
thereabouts is that it implicitly reduces the scope of a variable (without
needing to create new blocks.) This can sometimes catch some pretty serious
errors.

-hpa