some people like void main()
I was at the local Dymocks bookstore the other day looking for my next C++ book when I came across a book by SAMS (i forgot the name) that teaches Visual C++. I had a quick flick through it and was amazed to see that all applicable examples had used void main() instead of int main(). I know ultimately its not a big deal in terms of functionality but Im trying to find out is there something I missed here? I mean, if the author is good enough to write a book that supposedly teaches C++ then you'd think he'd be familiar with standard C++ 'etiquette'.
Or again I emphasize I may be missing something... (which i usually do) :)
Re: some people like void main()
Quote:
Originally posted by Panopticon
I was at the local Dymocks bookstore the other day looking for my next C++ book when I came across a book by SAMS (i forgot the name) that teaches Visual C++. I had a quick flick through it and was amazed to see that all applicable examples had used void main() instead of int main(). I know ultimately its not a big deal in terms of functionality but Im trying to find out is there something I missed here? I mean, if the author is good enough to write a book that supposedly teaches C++ then you'd think he'd be familiar with standard C++ 'etiquette'.
Or again I emphasize I may be missing something... (which i usually do) :)
It's not just etiquette, it's literally wrong. Does that mean that the whole book is bad? Not necissarily, but it just goes to show you that even though someone may write a book on a particular topic, it doesn't automatically make them an expert.
What Stroustrup has to say :)
Can I write "void main()"?
The definition
void main() { /* ... */ }
is not and never has been C++, nor has it even been C. See the ISO C++ standard 3.6.1[2] or the ISO C standard 5.1.2.2.1. A conforming implementation accepts
int main() { /* ... */ }
and
int main(int argc, char* argv[]) { /* ... */ }
A conforming implementation may provide more versions of main(), but they must all have return type int. The int returned by main() is a way for a program to return a value to "the system" that invokes it. On systems that doesn't provide such a facility the return value is ignored, but that doesn't make "void main()" legal C++ or legal C. Even if your compiler accepts "void main()" avoid it, or risk being considered ignorant by C and C++ programmers.
-----------------------
Now we can bury this question :)
-----------------------