Originally Posted by
dwks
There was a thread here a while ago where someone (MacGyver, I think) showed that int main() is actually better than int main(void).
Yikes, no!
From the FAQ:
http://faq.cprogramming.com/cgi-bin/...&id=1043284376
The only versions of main() that has the blessing of the C standard for both C89/C90 and C99 is this:
Code:
int main(void);
int main(int argc, char *argv[]);
Unfortunately, I do not believe the C++ standard allows void to be a type of C++ that main() can accept, because C and C++ have totally different meaning with regard empty arguments in a function. C takes an empty argument function to mean that the function has an unknown number of arguments and C++ takes it to mean that the function has no arguments.
Hence the only true versions of main() in C++ is:
Code:
int main();
int main(int argc, char *argv[]);
So hence, the only version of main() which I think fits for both C89/C90, C99, and C++ is this:
Code:
int main(int argc, char *argv[]);
Now someone contradicted me the last time I stated this, but I don't remember the particulars. If someone has something definite on any of this, that would be great.
Since compilers are usually pretty loose with regard to main()'s return type and parameters, some will, no doubt, feel perfectly fine with arbitrary declarations of main().
Originally Posted by
dwks
In any case, the implicit int rule is deprecated in newer versions of C, and so the OP should use int. Returning zero is probably a good idea too.
Agreed.