h2o / picohttpparser

tiny HTTP parser written in C (used in HTTP::Parser::XS et al.)
1.82k stars 245 forks source link

Warnings in compilation for C89 (ANSI C) #79

Closed felipemarkson closed 7 months ago

felipemarkson commented 8 months ago

If you try to compile picohttpparser.c using C89 you get a couple of warnings:

gcc -std=c89 -pedantic -c picohttpparser.c

OUTPUT

picohttpparser.c: In function ‘parse_headers’:
picohttpparser.c:336:9: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
  336 |         const char *value;
      |         ^~~~~
picohttpparser.c:342:9: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
  342 |         const char *value_end = value + value_len;
      |         ^~~~~

As picohttpparser does not allocate memory, it is great to use with micro-controllers which may not support C99.

This issue is to solve these warning.

kazuho commented 8 months ago

Thank you for opening the issue and filing a PR.

In our coding style, we intentionally allow use of some C99 dialects; see https://github.com/h2o/h2o/wiki/Coding-Style.

Would it be possible for you to solve the issue by changing the compiler options?

oerdnj commented 8 months ago

Just to chime in as a user of the library. C99 is now 25 years old. Lack of tooling for fringe platforms should not be an argument to compromise on the code clarity and all features listed in #2188 greatly improve the code style.

As a matter of fact, I am big fan of all C code should gradually move to at least C11/C17, but that’s another story ;)

felipemarkson commented 8 months ago

In our coding style, we intentionally allow use of some C99 dialects; see https://github.com/h2o/h2o/wiki/Coding-Style.

@kazuho Oh! I hadn't realized that. Since the warning is caused by only three lines of code, I thought this library supported ANSI C. PR #80 should be rejected then and I will close this issue if you prefer.

Thanks.