Skip to content

Commit 82dd01d

Browse files
avargitster
authored andcommitted
CodingGuidelines: allow declaring variables in for loops
Since 44ba10d (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 cb26077 (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 442c27d commit 82dd01d

File tree

2 files changed

+2
-15
lines changed

2 files changed

+2
-15
lines changed

Documentation/CodingGuidelines

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -232,18 +232,12 @@ For C programs:
232232
. since early 2021 with 765dc168882, we have been using variadic
233233
macros, mostly for printf-like trace and debug macros.
234234

235-
These used to be forbidden, but we have not heard any breakage
236-
report, and they are assumed to be safe.
235+
. since late 2021 with 44ba10d6, we have had variables declared in
236+
the for loop "for (int i = 0; i < 10; i++)".
237237

238238
- Variables have to be declared at the beginning of the block, before
239239
the first statement (i.e. -Wdeclaration-after-statement).
240240

241-
- Declaring a variable in the for loop "for (int i = 0; i < 10; i++)"
242-
is still not allowed in this codebase. We are in the process of
243-
allowing it by waiting to see that 44ba10d6 (revision: use C99
244-
declaration of variable in for() loop, 2021-11-14) does not get
245-
complaints. Let's revisit this around November 2022.
246-
247241
- NULL pointers shall be written as NULL, not as 0.
248242

249243
- When declaring pointers, the star sides with the variable

revision.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,6 @@ static inline int want_ancestry(const struct rev_info *revs);
4747
void show_object_with_name(FILE *out, struct object *obj, const char *name)
4848
{
4949
fprintf(out, "%s ", oid_to_hex(&obj->oid));
50-
/*
51-
* This "for (const char *p = ..." is made as a first step towards
52-
* making use of such declarations elsewhere in our codebase. If
53-
* it causes compilation problems on your platform, please report
54-
* it to the Git mailing list at [email protected]. In the meantime,
55-
* adding -std=gnu99 to CFLAGS may help if you are with older GCC.
56-
*/
5750
for (const char *p = name; *p && *p != '\n'; p++)
5851
fputc(*p, out);
5952
fputc('\n', out);

0 commit comments

Comments
 (0)