C programming faqs里面的
Can I declare main as void, to shut off these annoying ``main returns no value'' messages?
No. main must be declared as returning an int, and as taking either zero or two arguments, of the
appropriate types. If you're calling exit() but still getting warnings, you may have to insert a
redundant return statement (or use some kind of ``not reached'' directive, if available).
Declaring a function as void does not merely shut off or rearrange warnings: it may also result in a
different function call/return sequence, incompatible with what the caller (in main's case, the C run-tim
startup code) expects.
(Note that this discussion of main pertains only to ``hosted'' implementations; none of it applies to
``freestanding'' implementations, which may not even have main. However, freestanding
implementations are comparatively rare, and if you're using one, you probably know it. If you've never
heard of the distinction, you're probably using a hosted implementation, and the above rules apply.)
I believe that declaring void main() can't fail, since I'm calling exit instead of returning, and
anyway my operating system ignores a program's exit/return status.
It doesn't matter whether main returns or not, or whether anyone looks at the status; the problem is that
when main is misdeclared, its caller (the runtime startup code) may not even be able to call it correctly
(due to the potential clash of calling conventions; see question 11.12). Your operating system may ignore
the exit status, and void main() may work for you, but it is not portable and not correct.
The book I've been using, C Programing for the Compleat Idiot, always uses void main().
Perhaps its author counts himself among the target audience. Many books unaccountably use void
main() in examples. They're wrong.