From: Ferruh Yigit <ferruh.yigit@amd.com>
To: Thomas Monjalon <thomas@monjalon.net>
Cc: <dev@dpdk.org>, Bruce Richardson <bruce.richardson@intel.com>,
David Marchand <david.marchand@redhat.com>
Subject: [PATCH v2] devtools: allow variable declaration inside for loop
Date: Wed, 3 May 2023 11:30:53 +0100 [thread overview]
Message-ID: <20230503103053.3087445-1-ferruh.yigit@amd.com> (raw)
In-Reply-To: <20230503095018.1710769-1-ferruh.yigit@amd.com>
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 <ferruh.yigit@amd.com>
---
Cc: Bruce Richardson <bruce.richardson@intel.com>
Cc: David Marchand <david.marchand@redhat.com>
v2:
* Update coding convention too
---
devtools/checkpatches.sh | 8 --------
doc/guides/contributing/coding_style.rst | 1 +
2 files changed, 1 insertion(+), 8 deletions(-)
diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh
index 15d5d6709445..b5baf6f2b161 100755
--- a/devtools/checkpatches.sh
+++ b/devtools/checkpatches.sh
@@ -78,14 +78,6 @@ check_forbidden_additions() { # <patch>
-f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \
"$1" || res=1
- # forbid variable declaration inside "for" loop
- awk -v FOLDERS='.' \
- -v EXPRESSIONS='for[[:space:]]*\\((char|u?int|unsigned|s?size_t)' \
- -v RET_ON_FAIL=1 \
- -v MESSAGE='Declaring a variable inside for()' \
- -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \
- "$1" || res=1
-
# refrain from new additions of 16/32/64 bits rte_atomicNN_xxx()
awk -v FOLDERS="lib drivers app examples" \
-v EXPRESSIONS="rte_atomic[0-9][0-9]_.*\\\(" \
diff --git a/doc/guides/contributing/coding_style.rst b/doc/guides/contributing/coding_style.rst
index 89db6260cfbf..e18b8d4439ea 100644
--- a/doc/guides/contributing/coding_style.rst
+++ b/doc/guides/contributing/coding_style.rst
@@ -558,6 +558,7 @@ Local Variables
* 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.
* When declaring variables in functions, multiple variables per line are OK.
However, if multiple declarations would cause the line to exceed a reasonable line length, begin a new set of declarations on the next line rather than using a line continuation.
* Be careful to not obfuscate the code by initializing variables in the declarations, only the last variable on a line should be initialized.
--
2.34.1
next prev parent reply other threads:[~2023-05-03 10:31 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-03 9:50 [PATCH v1] " Ferruh Yigit
2023-05-03 10:02 ` Bruce Richardson
2023-05-03 10:23 ` Ferruh Yigit
2023-05-03 10:30 ` Ferruh Yigit [this message]
2023-05-03 10:57 ` [PATCH v2] " Bruce Richardson
2023-05-03 12:19 ` Morten Brørup
2023-05-03 15:01 ` Thomas Monjalon
2023-05-03 15:06 ` Tyler Retzlaff
2023-07-20 4:05 ` Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230503103053.3087445-1-ferruh.yigit@amd.com \
--to=ferruh.yigit@amd.com \
--cc=bruce.richardson@intel.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=thomas@monjalon.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).