git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH v2 3/5] CodingGuidelines: allow declaring variables in for loops
Date: Mon, 10 Oct 2022 13:37:58 -0700	[thread overview]
Message-ID: <20221010203800.2154698-4-gitster@pobox.com> (raw)
In-Reply-To: <20221010203800.2154698-1-gitster@pobox.com>

From: Ævar Arnfjörð Bjarmason <avarab@gmail.com>

Since 44ba10d6712 (revision: use C99 declaration of variable in for()
loop, 2021-11-14) released with v2.35.0 we've had a variable declared
with in a for loop.

Since then we've had inadvertent follow-ups to that with at least
cb2607759e2 (merge-ort: store more specific conflict information,
2022-06-18) released with v2.38.0.

As November 2022 is within the window of this upcoming release,
let's update the guideline to allow this.  We can have the promised
"revisit" discussion while this patch cooks, and drop it if it turns
out that it is still premature, which is not expected to happen at
this moment.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 Documentation/CodingGuidelines | 10 ++--------
 revision.c                     |  7 -------
 2 files changed, 2 insertions(+), 15 deletions(-)

diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
index 8afda28cfc..f9affc4050 100644
--- a/Documentation/CodingGuidelines
+++ b/Documentation/CodingGuidelines
@@ -232,18 +232,12 @@ For C programs:
    . since early 2021 with 765dc168882, we have been using variadic
      macros, mostly for printf-like trace and debug macros.
 
-   These used to be forbidden, but we have not heard any breakage
-   report, and they are assumed to be safe.
+   . since late 2021 with 44ba10d6, we have had variables declared in
+     the for loop "for (int i = 0; i < 10; i++)".
 
  - Variables have to be declared at the beginning of the block, before
    the first statement (i.e. -Wdeclaration-after-statement).
 
- - Declaring a variable in the for loop "for (int i = 0; i < 10; i++)"
-   is still not allowed in this codebase.  We are in the process of
-   allowing it by waiting to see that 44ba10d6 (revision: use C99
-   declaration of variable in for() loop, 2021-11-14) does not get
-   complaints.  Let's revisit this around November 2022.
-
  - NULL pointers shall be written as NULL, not as 0.
 
  - When declaring pointers, the star sides with the variable
diff --git a/revision.c b/revision.c
index 36e31942ce..8f2623b3b5 100644
--- a/revision.c
+++ b/revision.c
@@ -47,13 +47,6 @@ static inline int want_ancestry(const struct rev_info *revs);
 void show_object_with_name(FILE *out, struct object *obj, const char *name)
 {
 	fprintf(out, "%s ", oid_to_hex(&obj->oid));
-	/*
-	 * This "for (const char *p = ..." is made as a first step towards
-	 * making use of such declarations elsewhere in our codebase.  If
-	 * it causes compilation problems on your platform, please report
-	 * it to the Git mailing list at git@vger.kernel.org. In the meantime,
-	 * adding -std=gnu99 to CFLAGS may help if you are with older GCC.
-	 */
 	for (const char *p = name; *p && *p != '\n'; p++)
 		fputc(*p, out);
 	fputc('\n', out);
-- 
2.38.0-167-gf9a88ca9e9


  parent reply	other threads:[~2022-10-10 20:38 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-07  9:30 [PATCH 0/5] CodingGuidelines: various C99 updates Ævar Arnfjörð Bjarmason
2022-10-07  9:30 ` [PATCH 1/5] CodingGuidelines: update for C99 Ævar Arnfjörð Bjarmason
2022-10-07 18:08   ` Junio C Hamano
2022-10-07  9:30 ` [PATCH 2/5] CodingGuidelines: mention dynamic C99 initializer elements Ævar Arnfjörð Bjarmason
2022-10-07  9:30 ` [PATCH 3/5] CodingGuidelines: allow declaring variables in for loops Ævar Arnfjörð Bjarmason
2022-10-07 18:12   ` Junio C Hamano
2022-10-07  9:30 ` [PATCH 4/5] CodingGuidelines: mention C99 features we can't use Ævar Arnfjörð Bjarmason
2022-10-07 18:13   ` Junio C Hamano
2022-10-07  9:30 ` [PATCH 5/5] CodingGuidelines: recommend against unportable C99 struct syntax Ævar Arnfjörð Bjarmason
2022-10-07 17:54 ` [PATCH 0/5] CodingGuidelines: various C99 updates Junio C Hamano
2022-10-07 18:15   ` Junio C Hamano
2022-10-10 20:37 ` [PATCH v2 0/5] CodingGUidelines: " Junio C Hamano
2022-10-10 20:37   ` [PATCH v2 1/5] CodingGuidelines: update for C99 Junio C Hamano
2022-10-10 20:37   ` [PATCH v2 2/5] CodingGuidelines: mention dynamic C99 initializer elements Junio C Hamano
2022-10-10 20:37   ` Junio C Hamano [this message]
2022-10-10 20:37   ` [PATCH v2 4/5] CodingGuidelines: mention C99 features we can't use Junio C Hamano
2022-10-10 20:38   ` [PATCH v2 5/5] CodingGuidelines: recommend against unportable C99 struct syntax Junio C Hamano
2022-10-11  0:09     ` Jeff King
2022-10-11  0:26       ` Junio C Hamano
2022-10-11  0:39         ` Jeff King
2022-10-11  8:30         ` Ævar Arnfjörð Bjarmason
2022-10-11 15:01           ` Junio C Hamano

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221010203800.2154698-4-gitster@pobox.com \
    --to=gitster@pobox.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).