Possible Duplicate:
What is the proper declaration of main?
I am working on my C skills and I have noticed that
int main( int argc, char *argv[] )
and
return (EXIT_SUCCESS)
instead of
int main() and return 0
Why is this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you are going to ignore the argument list, it is reasonable and sensible to use:
The standards bless this usage, as well as the one with arguments. You get a warning from GCC if you compile with
-Wstrict-prototypesand don’t include thevoid, so I write thevoid. C++ is different here.As for
return EXIT_SUCCESS;, there seems to be little benefit to it in general; I continue to writereturn 0;at the end of amain()function, even though C99 permits you to omit any return there (and it then behaves as if you wrotereturn 0;).Aside: Note that §5.1.2.2.3 clearly indicates that the C standard allows an implementation to permit return types for
main()other thanint(unlike the C++ standard, which expressly forbids a return type other thanint). However, as Jens rightly points out, a non-intreturn type frommainis only allowed if the implementation explicitly documents that it is allowed, and the documentation will probably place limits on what is allowed.