]> granicus.if.org Git - nethack/commitdiff
fix #K3863 - replace 'for (int i=0;...' in core
authorPatR <rankin@nethack.org>
Mon, 20 Feb 2023 20:22:14 +0000 (12:22 -0800)
committerPatR <rankin@nethack.org>
Mon, 20 Feb 2023 20:22:14 +0000 (12:22 -0800)
The Makefiles and some of the hints have already been updated to
specify that C99 is required in response to #K3863.  The code was
evidently being compiled in the default mode of an old version of
gcc and that mode complained that C99 was required to specify a
declaration in the initializer clause of a
'for(initialize;test;update)statement'.  Other C99 features used
by nethack were apparently accepted as extensions in the default
conformance mode.

There's only one such declaration in the core code so replace it
with a separate declaration and ordinary 'for' loop.

win/Qt/{lots}.cpp and win/win32/{few}.c have these declarations but
the core didn't.

src/cmd.c

index 655f15794a440629a9dcdc5a0367ac17c48bbf6b..067dfd811675808ff3ec267d705dde687eb67839 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -4059,14 +4059,14 @@ RESTORE_WARNING_FORMAT_NONLITERAL
 static int
 wiz_display_macros(void)
 {
+    static const char display_issues[] = "Display macro issues:";
     char buf[BUFSZ];
     winid win;
-    int test, trouble = 0, no_glyph = NO_GLYPH, max_glyph = MAX_GLYPH;
-    static const char *const display_issues = "Display macro issues:";
+    int glyph, test, trouble = 0, no_glyph = NO_GLYPH, max_glyph = MAX_GLYPH;
 
     win = create_nhwindow(NHW_TEXT);
 
-    for (int glyph = 0; glyph < MAX_GLYPH; ++glyph) {
+    for (glyph = 0; glyph < MAX_GLYPH; ++glyph) {
         /* glyph_is_cmap / glyph_to_cmap() */
         if (glyph_is_cmap(glyph)) {
             test = glyph_to_cmap(glyph);