cgccclangfunction-prototypesc23

Regarding mainstream compilers and int main(){} in C23


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.

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?


Solution

  • 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.