0

My program:

int main(){}

In upcoming C23, non-prototype and "K&R style" functions are removed. I realize that C23 is not yet formally released, but the current behavior of gcc and clang is confusing me.

  • Compiling the above with gcc (trunk) -std=c2x -pedantic-errors -Wall -Wextra:
    no diagnostics.
  • Compiling the above with clang 16.0.0 -std=c2x -pedantic-errors -Wall -Wextra:
    no diagnostics.
  • Compiling the above with clang 16.0.0 -pedantic-errors -Wall -Wextra:

    error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]

How am I to make any sense of this? I can understand if gcc has not yet implemented this, since C23 is after all not yet released, but why is clang giving the warning when I don't specify -std=c2x?

Lundin
  • 195,001
  • 40
  • 254
  • 396

2 Answers2

3

It appears that I have missed this part in C23 (draft N3096) 6.7.6.3/13:

For a function declarator without a parameter type list: the effect is as if it were declared with a parameter type list consisting of the keyword void. A function declarator provides a prototype for the function.

That is, C23 will behave as C++ already does.

Lundin
  • 195,001
  • 40
  • 254
  • 396
2

When you use clang 16.0.0 and don't use -std=c2x it defaults to some version that is not c2x (probably c11, maybe c17).

In that version, your program has a function declaration without a prototype, which is deprecated in all versions of C (including that one).

In C2X, they removed the possibility of declaring functions without prototypes. Every function declaration has a prototype. So this same code is a function declaration with a prototype with no parameters.

user253751
  • 57,427
  • 7
  • 48
  • 90