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]

Regards,
/Bruce

Reply via email to