C23 introduced new semantics in function declarators:
6.7.6.3 Function declarators
[...]
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.
This seems to imply that a function definition with an empty parameter list can be written equivalently with ()
or (void)
.
Yet this equivalence does not seem guaranteed for the main
function:
5.1.2.2.1 Program startup
The function called at program startup is named
main
. The implementation declares no prototype for this function. It shall be defined with a return type ofint
and with no parameters:int main(void) { /* ... */ }
or with two parameters (referred to here as
argc
andargv
, though any names may be used, as they are local to the function in which they are declared):int main(int argc, char *argv[]) { /* ... */ }
or equivalent or in some other implementation-defined manner.
This does not seem to guarantee that int main() { /* ... */ }
is a valid definition for main
, or does equivalent cover this variant?
It troubles me that the 2 examples in C17 that use the syntax int main()
(in 6.5.3.4 and 6.7.6.3) have been changed to use int main(void)
in the latest C23 draft.
Yes, for function declarations.
C23 draft N1570 has the revised specification:
I understand this to apply to all functions including
main()
.The specifications about
main
do not restrict this.