23/03/2020 14:59, Bruce Richardson:
> On Mon, Feb 17, 2020 at 11:26:54PM +0100, Thomas Monjalon wrote:
> > Some compilers raise an error when declaring a variable
> > in the middle of a function. This is a C99 allowance.
> > Even if DPDK switches globally to C99 or C11 standard,
> > the coding rules are for declarations at the beginning
> > of a block:
> > http://doc.dpdk.org/guides/contributing/coding_style.html#local-variables
> > 
> > This coding style is enforced by adding a check of
> > the common patterns like "for (int i;"
> > 
> 
> Could we, or should we, not also revisit the coding standards for this.
> Those standards are quite old now, and could do with being updated to take
> account of things like the newer C standards. Obviously for consistency
> reasons any changes should not be major, but I don't think we should view
> the guidelines as set in stone either.
> 
> For this particular issue, I think generally having all declarations at the
> beginning of a block is the right thing to do, however, I would support
> relaxing this rule in a couple of scenarios, specifically:
> 
> * declaring a variable like i in a for loop, i.e. the case above
> * using const on a variable declaration, marking it as const at first
>   assignment [because I take the view that increased use of const is almost
>   always a good thing]

I would tend to agree in general for updating guidelines,
and especially in this case.
But because we are not enforcing C99 (or C11) when compiling,
some users are still trying to compile with old compilers.
As a result, a declaration in a for loop will break compilation
with some compilers:
        http://git.dpdk.org/dpdk/commit/?id=bc3282125b

I am OK either way:
        - switch globally to C99/C11
        - or forbid declaration in for loop
I took the second option because it is easier,
and because it maximizes our compiler tolerance.


Reply via email to