Lundin
Lundin

Reputation: 214890

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?

Upvotes: 0

Views: 603

Answers (2)

Lundin
Lundin

Reputation: 214890

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.

Upvotes: 3

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.

Upvotes: 2

Related Questions