diff mbox series

[1/3] tools: move initial declarations out of 'for' loop

Message ID 1551764896-8453-1-git-send-email-yamada.masahiro@socionext.com (mailing list archive)
State New, archived
Headers show
Series [1/3] tools: move initial declarations out of 'for' loop | expand

Commit Message

Masahiro Yamada March 5, 2019, 5:48 a.m. UTC
When I was trying to compile this code for hostprogs-y notation of
Kbuild, I was hit by the following error.

  error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode

This is because KBUILD_HOSTCFLAGS specifies -std=gnu89 whereas the tools
Makefile compiles it with -std=gnu99.

Of course, it would be possible to pass -std=gnu99 per file, but it
shouldn't hurt to fix the C code.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

 tools/lib/subcmd/parse-options.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/tools/lib/subcmd/parse-options.c b/tools/lib/subcmd/parse-options.c
index dbb9efb..1bd858a2 100644
--- a/tools/lib/subcmd/parse-options.c
+++ b/tools/lib/subcmd/parse-options.c
@@ -630,6 +630,7 @@  int parse_options_subcommand(int argc, const char **argv, const struct option *o
 			const char *const subcommands[], const char *usagestr[], int flags)
 {
 	struct parse_opt_ctx_t ctx;
+	int i;
 
 	/* build usage string if it's not provided */
 	if (subcommands && !usagestr[0]) {
@@ -637,7 +638,7 @@  int parse_options_subcommand(int argc, const char **argv, const struct option *o
 
 		astrcatf(&buf, "%s %s [<options>] {", subcmd_config.exec_name, argv[0]);
 
-		for (int i = 0; subcommands[i]; i++) {
+		for (i = 0; subcommands[i]; i++) {
 			if (i)
 				astrcat(&buf, "|");
 			astrcat(&buf, subcommands[i]);
@@ -663,7 +664,7 @@  int parse_options_subcommand(int argc, const char **argv, const struct option *o
 		exit(130);
 	case PARSE_OPT_LIST_SUBCMDS:
 		if (subcommands) {
-			for (int i = 0; subcommands[i]; i++)
+			for (i = 0; subcommands[i]; i++)
 				printf("%s ", subcommands[i]);
 		}
 		putchar('\n');