Skip to content

Commit

Permalink
Merge branch 'jc/c99-var-decl-in-for-loop' into jch
Browse files Browse the repository at this point in the history
Weather balloon to break comiplers that do not grok variable
declaration in the for() loop.

* jc/c99-var-decl-in-for-loop:
  revision: use C99 declaration of variable in for() loop
  • Loading branch information
gitster committed Nov 23, 2021
2 parents b1f0e5a + 696e04b commit caf46ee
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,7 @@ endif
# Set CFLAGS, LDFLAGS and other *FLAGS variables. These might be
# tweaked by config.* below as well as the command-line, both of
# which'll override these defaults.
# Older versions of GCC may require adding "-std=gnu99" at the end.
CFLAGS = -g -O2 -Wall
LDFLAGS =
CC_LD_DYNPATH = -Wl,-rpath,
Expand Down
11 changes: 8 additions & 3 deletions revision.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,15 @@ static inline int want_ancestry(const struct rev_info *revs);

void show_object_with_name(FILE *out, struct object *obj, const char *name)
{
const char *p;

fprintf(out, "%s ", oid_to_hex(&obj->oid));
for (p = name; *p && *p != '\n'; p++)
/*
* 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);
}
Expand Down

0 comments on commit caf46ee

Please sign in to comment.