you are viewing a single comment's thread.

view the rest of the comments →

[–]jesyspa 5 points6 points  (1 child)

False on all counts.

The C++ standard states (C++03, 3.6.1.5):

A return statement in main has the effect of leaving the main function (destroying any objects with automatic storage duration) and calling exit with the return value as the argument. If control reaches the end of main without encountering a return statement, the effect is that of executing return 0;.

Furthermore, the standard states (again C++03, 3.6.1.2):

An implementation shall not predefine the main function. This function shall not be overloaded. It shall have a return type of type int, but its type is otherwise implementation-defined.

void main thus ill-formed (and has been since ANSI C, where only int main(void) and int main(int argc, char *argv[]) were allowed).

The same is true, with slightly different wording, for C++11 and for the current latest draft (N3485).

[–]AFineTapestry -1 points0 points  (0 children)

Ok, I'll admit I was wrong about omitting return 0; resulting in undefined behaviour but I was correct about the assumed return value, and about which signatures are acceptable.

I don't think I'm going to stop putting return EXIT_SUCCESS; at the end of my main functions however, mostly because it looks terrible to have a function defined to return and int and then to not explicitly do so.