Hacker News new | ask | show | jobs
by _kst_ 761 days ago
Except that in C (at least prior to C23), it should be "int main(void)".

I'm fairly sure that all existing C compilers will quietly accept "int main()", but there's an argument that "int main()" causes the program to have undefined behavior. "int main(void)" is the form documented in the standard.

And the "return 0;" is unnecessary both in C++ and in all versions of C starting with C99. (Some will argue that it's better style to be explicit.)

These are admittedly minor points.

1 comments

Meh, the program execution language about main() has included from the beginning an escape hatch: it allows main to be defined “in some other implementation-defined manner.” “int main(void)” is one of four forms documented in the standard (or one of two specific shapes of code; the other two are “or equivalent” and “or in some other implementation-defined manner.”