BNFC / bnfc

BNF Converter
http://bnfc.digitalgrammars.com/
586 stars 165 forks source link

Don't use C99 syntax in for loop for smoother make #274

Closed 7890 closed 4 years ago

7890 commented 4 years ago
diff --git a/source/src/BNFC/Backend/C/CFtoFlexC.hs b/source/src/BNFC/Backend/C/CFtoFlexC.hs
index 5f56765..85f7cc1 100644
--- a/source/src/BNFC/Backend/C/CFtoFlexC.hs
+++ b/source/src/BNFC/Backend/C/CFtoFlexC.hs
@@ -98,7 +98,8 @@ prelude name = unlines
    "{",
    "  loc->first_line = loc->last_line;",
    "  loc->first_column = loc->last_column;",
-   "  for (int i = 0; text[i] != '\\0'; ++i) {",
+   "  int i;",
+   "  for (i = 0; text[i] != '\\0'; ++i) {",
    "      if (text[i] == '\\n') {",
    "          ++loc->last_line;",
    "          loc->last_column = 0; ",

This helped to make without errors.

andreasabel commented 4 years ago

Sure, approved. (I wasn't aware that this form is not standard. On the other hand, I also did not write this code and am not intimately familiar with C in the first place.)

Thanks for reporting! (A PR would have given bonus points.)