Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support of old C89 standard #163

Closed
mikir opened this issue Nov 23, 2022 · 2 comments
Closed

Support of old C89 standard #163

mikir opened this issue Nov 23, 2022 · 2 comments

Comments

@mikir
Copy link

mikir commented Nov 23, 2022

Not sure if support of old C89 standard has been cancelled but if this is not that case, the last release has introduced some small violations in modules pcre2_compile.c and pcre2_script_run.c. Examples:

pcre2_compile.c: In function 'compile_branch':
pcre2_compile.c:5857:13: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
             for (int i = 0; i < 32; i++) pbits[i] |= cbits[(int)i + taboffset];
             ^
pcre2_compile.c:5857:13: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code
pcre2_compile.c:5859:22: error: redefinition of 'i'
             for (int i = 0; i < 32; i++) pbits[i] &= ~cbits[(int)i + taboffset];
                      ^
pcre2_compile.c:5857:22: note: previous definition of 'i' was here
             for (int i = 0; i < 32; i++) pbits[i] |= cbits[(int)i + taboffset];
                      ^
pcre2_compile.c:5859:13: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
             for (int i = 0; i < 32; i++) pbits[i] &= ~cbits[(int)i + taboffset];
             ^

pcre2_script_run.c: In function '_pcre2_script_run_8':
pcre2_script_run.c:109:1: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
 for (int i = 0; i < FULL_MAPSIZE; i++) require_map[i] = 0;
 ^
pcre2_script_run.c:109:1: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code
pcre2_script_run.c:248:7: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
       for (int i = 0; i < FULL_MAPSIZE; i++)
       ^
pcre2_script_run.c:285:9: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
         for (int i = 0; i < FULL_MAPSIZE; i++) require_map[i] &= map[i];

Please consider to change it. Or feel free to close it without any actions if C89 violations are not an issue any more.

@PhilipHazel
Copy link
Collaborator

Declarations in "for" statements are in C99, so have been standardized for over 20 years. I am happy to move to C99, unless there are very strong objections.

@mikir
Copy link
Author

mikir commented Nov 23, 2022

OK, I see. No objections. :-)

@mikir mikir closed this as completed Nov 23, 2022
carenas added a commit to carenas/pcre2 that referenced this issue Jan 15, 2023
Recent code uses C99 syntax (as reported in PCRE2Project#163, and therefore it
will fail to build unless C99 (or higher) support is required by the
compiler (gcc >= 5 does it by default).

For those unfortunate to need an older compiler that does require a
flag to enable that, make sure that both autoconf and cmake make it
explicit.

While testing the change with the ancient autoconf version listed as
a prerequisite, noticed that the LT_INIT syntax introduced with 91485e5
(Update configure.ac for latest version of autoconf., 2021-02-02), was
not supported, so update the autoconf minimum as well.
PhilipHazel pushed a commit that referenced this issue Jan 19, 2023
Recent code uses C99 syntax (as reported in #163, and therefore it
will fail to build unless C99 (or higher) support is required by the
compiler (gcc >= 5 does it by default).

For those unfortunate to need an older compiler that does require a
flag to enable that, make sure that both autoconf and cmake make it
explicit.

While testing the change with the ancient autoconf version listed as
a prerequisite, noticed that the LT_INIT syntax introduced with 91485e5
(Update configure.ac for latest version of autoconf., 2021-02-02), was
not supported, so update the autoconf minimum as well.
mdounin added a commit to freenginx/nginx that referenced this issue Aug 12, 2024
Note that PCRE2 10.40 and newer versions require C99 support, as it now
uses "for (int i = 0; ...)" constructs[1], and thus cannot be compiled
with MSVC 2010 and older versions anymore.

[1] PCRE2Project/pcre2#163
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants