Coding Style for local variables
Bruce Richardson
bruce.richardson at intel.com
Mon Jun 17 16:38:48 CEST 2024
On Mon, Jun 10, 2024 at 05:10:01PM +0200, Morten Brørup wrote:
> The coding style guide says:
>
> "Variables should be declared at the start of a block of code rather than in the middle. The exception to this is when the variable is const in which case the declaration must be at the point of first use/assignment. Declaring variable inside a for loop is OK."
>
> Since DPDK switched to C11, variables can be declared where they are used, which reduces the risk of using effectively uninitialized variables. "Effectively uninitialized" means initialized to 0 or NULL where declared, to silence any compiler warnings about the use of uninitialized variables.
>
> Can we please agree to remove the recommendation/requirement to declare variables at the start of a block of code?
>
+1
Declaring variables at point of first use is generally easier to read, and
makes things far simpler when commenting out blocks of code for devel or
debugging purposes - avoid those unused variable warnings.
/Bruce
More information about the dev
mailing list