From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0ED5342A50; Wed, 3 May 2023 17:06:16 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 980A042B8E; Wed, 3 May 2023 17:06:15 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id CD3AE41144 for ; Wed, 3 May 2023 17:06:13 +0200 (CEST) Received: by linux.microsoft.com (Postfix, from userid 1086) id 1A4AF21C424A; Wed, 3 May 2023 08:06:13 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 1A4AF21C424A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1683126373; bh=tmZ6OMAPC6TbPUiZstKB+DEwgfeCuJfu8GLOid6BkQM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=nb8Jydpqkhn4X/Hfd36plGEAVFYlTKNKsIPrzNPV+mZ6MXv1EaLY4wuRZ5dQpQz7F es8cwb5M3ZFGkEXAT/UVHu9kI+D3PjBrsFeFkPIh9vpiWjHRga+FcBrulvO5qypLAE G4O/+uh096BkiFDgkkY3arptbUWNDqb7uiw27Jq0= Date: Wed, 3 May 2023 08:06:13 -0700 From: Tyler Retzlaff To: Thomas Monjalon Cc: Bruce Richardson , Ferruh Yigit , Morten =?iso-8859-1?Q?Br=F8rup?= , dev@dpdk.org, David Marchand Subject: Re: [PATCH v2] devtools: allow variable declaration inside for loop Message-ID: <20230503150613.GA7537@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> References: <20230503095018.1710769-1-ferruh.yigit@amd.com> <98CBD80474FA8B44BF855DF32C47DC35D878DC@smartserver.smartshare.dk> <2878762.e9J7NaK4W3@thomas> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <2878762.e9J7NaK4W3@thomas> User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Wed, May 03, 2023 at 05:01:01PM +0200, Thomas Monjalon wrote: > 03/05/2023 14:19, Morten Brørup: > > > From: Bruce Richardson [mailto:bruce.richardson@intel.com] > > > Sent: Wednesday, 3 May 2023 12.57 > > > > > > On Wed, May 03, 2023 at 11:30:53AM +0100, Ferruh Yigit wrote: > > > > Declaring variable inside for loop is not supported via C89 and it was > > > > checked in checkpatch.sh via commit [1]. > > > > But as DPDK supported C standard is becoming C99/C11 [2], declaring > > > > variable inside loop can be allowed. > > > > > > > > [1] > > > > Commit 43e73483a4b8 ("devtools: forbid variable declaration inside > > > for") > > > > > > > > [2] > > > > https://dpdk.org/patch/121912 > > > > > > > > Signed-off-by: Ferruh Yigit > > > > --- > > > > Cc: Bruce Richardson > > > > Cc: David Marchand > > > > > > > > v2: > > > > * Update coding convention too > > > > --- > > > > > > Acked-by: Bruce Richardson > > > > Acked-by: Morten Brørup > > > > [...] > > > > > > @@ -558,6 +558,7 @@ Local Variables > > > > > > > > * Variables should be declared at the start of a block of code rather > > > than in the middle. > > > > > > I'd love to see this restriction removed in future too. Having a > > > variable > > > declared on first use in the middle of block I find a far easier way of > > > working as a) it saves scrolling to look for variable definitions and b) > > > it > > > makes it far easier when adding/removing blocks of code e.g. commenting > > > out > > > for testing, to have all the code together rather than having variables > > > at > > > the top to add/remove also. > > > > And c) Initializing the variables close to where they are used the first time reduces the risk of initializing them incorrectly. Especially when modifying a block of code, initialization of its variables might be missed if out of sight. (Although this is probably a consequence of "a)".) > > > > I consider it old style to only declare variables at the start of a block of code, and this style of coding should be considered obsolete. > > > > If you are really old (like me?), you might remember when function parameters were provided like this: > > > > int main(argc, argv) > > int argc; > > char *argv[]; > > { > > return(0); > > } heh, k&r C > > > > We have moved on from that to a more modern coding style a long time ago. We should also move on to a more modern coding style regarding variable declarations. > > Old men are used to look for variable types at the beginning of functions. > Having only new code adopting a different style may be confusing a little. > Note I'm not against it, just asking for more feedbacks. Acked-by: Tyler Retzlaff +1 for declare in minimum necessary scope +1 for declare at first use (enables more use of const) thank you!