L
Leor Zolman
I have often wondered where not only newbies, but book authors, got the
idea that void main() was any form of C at all. As you and Richard
correctly say, void main() was never used in any form of standard C,
and it wasn't used in K&R C either. (They simply used main().) Have
those people invented it out of thin air and then started convincing
themselves it was standard C?
Having been around C for a while, it doesn't seem like much of a
mystery to me how "void main" would have come into common use
(although I'd agree there's no excuse for thinking it was
"standard")... When void was introduced into the language, it finally
provided a way to define main() in a way that means "I'm not returning
anything". This could reasonably be labeled a questionable practice on
Unix (K&R's platform, where it is always trivial to test a process's
exit status one way or another from shell script or system calls).
However, just look at the hoops DOS batch files have always made
folks jump through in order to deal with an exit status. How many
people really understand how ERRORLEVEL works, or bother with it once
they learn? It makes sense in that context to "formally" inform people
reading the source code that they are off the hook WRT the exit status
of that program...and defining main to return void seems like a pretty
straightforward way to say that.
Another point in "void main"'s favor is simple consistency; if every
other function not returning anything can be declared with void, why
single out main to the contrary? Sure, we're talking about a
"different kind of return", but can you _imagine_ how that might not
sit well with folks learning C?
Time marches on, now in strict mode it's an error. That's fine with
me. As for anyone playing "C teacher" who uses it ... I really liked
the "Be afraid" comment ... ;-)
-leor
Leor Zolman
BD Software
(e-mail address removed)
www.bdsoft.com -- On-Site Training in C/C++, Java, Perl & Unix
C++ users: Download BD Software's free STL Error Message
Decryptor at www.bdsoft.com/tools/stlfilt.html