BartC said:
zemir is right. All these mis-declarations of 'main' are so widespread,
wouldn't it have been easier to have accepted them into the standard, than
have to be point them out every time? Especially as the compilers used don't
seem to be complaining.
It would have been slightly easier for programmers (what's so
bloody hard about writing it correctly in the first place?),
slightly more difficult for most implementers, and potentially
substantially more difficult for some implementers. Consider a
system where functions returning void and functions returning int
use significantly different calling conventions. If compilers were
required to accept "void main(void)", they'd have to do some kind
of fixup to make it look like "int main(void)" to the linker.
My own preference would have been to make defining "main" incorrectly
a constraint violation, not undefined behavior. For example:
Permit "int main(void)", "int main()", or "int main(int
argc, char *argv[])", or equivalent (with "or equivalent"
being defined sufficiently clearly). In addition, permit any
implementation-defined form; if a compiler wants to support
"void main(void)", it can do so. A definition of "main" that
doesn't match either one of the three explicitly permitted
forms or a form defined by the implementation violates
a constraint, requiring a diagnostic. (N.B.: This is a
hypothetical suggestion, not a description of the language as
it's actually defined.)
(Aside: I've argued that "int main()" is not equivalent to "int
main(void)", which is why I list it separately.)
Programs using "void main(void)" (as well as books that claim it's
valid), would have been weeded out over the years as they failed
to compile.
If the committee had chosen to require "void main(void)" to be
accepted as well, it wouldn't particularly bother me. I've never
argued that there's anything *intrinsically* wrong with it, just
that the standard doesn't support it.
But the fact remains that the language is defined the way it is,
and conforming to that definition shouldn't be at all difficult.
Failing to do so can *sometimes* indicate a lack of attention to
detail that can and should reduce the reader's trust in the rest
of the code (Schildt's books are a classic example).
IMHO, the blame lies not with the authors of the Standard, but with
the authors of books and tutorials (most of whom had access to the
Standard and therefore should have known better) who decided, for
no apparent reason, to tell their readers that "void main(void)"
is perfectly valid.
(That's also been mentioned so many times that I've no idea now whether you
are supposed to cast or not. (And no I'm not interested in knowing; the way
I do it seems to work so I don't care.))
If you don't care, why mention it? And since the vast majority of the
posts discussing it have been consistent, how can you be unaware of the
answer?