C++ standard lists allowed forms of main
. It doesn't list int main(void)
as an allowed form. But, it generally states that
The parameter list (void) is equivalent to the empty parameter list
Is int main(void)
an allowed form?
C++ standard lists allowed forms of main
. It doesn't list int main(void)
as an allowed form. But, it generally states that
The parameter list (void) is equivalent to the empty parameter list
Is int main(void)
an allowed form?
From N3936 standard draft:
3.6 Start and termination
3.6.1 Main function
2 An implementation shall not predefine the main function. This function shall not be overloaded. It shall have a declared return type of type int, but otherwise its type is implementation-defined. An implementation shall allow both
— a function of () returning int and
— a function of (int, pointer to pointer to char) returning int
as the type of main (8.3.5).
Then:
8.3.5 Functions
4 ... A parameter list consisting of a single unnamed parameter of non-dependent type void is equivalent to an empty parameter list. ...
Consequently,
int main(void)
is an allowed form of main
function.
In addition to comment of @Some programmer dude and @Edgar's answer, this is the part of N3936 draft which explains given difference between C++ and standard C:
C.1.7 Clause 8: declarators [diff.decl]
8.3.5
Change: In C++, a function declared with an empty parameter list takes no arguments. In C, an empty parameter list means that the number and type of the function arguments are unknown.
Example:
int f(); // means int f(void) in C++
// int f( unknown ) in C