'Is int main(void) { } a prototype?

I'm trying to understand declarations, definitions and prototypes. I came across the excellent post https://stackoverflow.com/a/41805712/1825603. I do, however, need some clarification, but because I do not have enough reputation to comment directly to the post, I will ask here...

The relevant section:

In definitions

void func1() { } // obsolescent

and

void func2(void) { }

The former declares and defines a function func1 that has no parameters and no prototype

The latter declares and defines a function func2 with a prototype that has no parameters.

When I see int main(void) { } as one of the Standard definitions for main in C99 5.1.2.2.1, I interpret from the above that it's "a declaration and definition of a function with a prototype that has no parameters". My confusion lies with C99 5.1.2.2.1, where it says, "The implementation declares no prototype for this function." By adding the void to int main() { }, does this mean the user-level code is declaring a prototype because the implementation hasn't? And if it's not a prototype, what is the effect of adding void?

Note: I believe I understand the reason the declaration int main(void); isn't used, ie, Declare main prototype, but don't think my question is a duplicate of this.

c


Solution 1:[1]

Is int main(void) { } a prototype?

Yes.

int main(void) { } is a function declaration and definition. As a declaration, it says nothing about the parameters. As a definition, it takes no parameters: i.e void.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1