So many times in bad books and online tutorials and so many people's code they use void main.The standard for such a long time now has said main is only an int function.Why do people still do this even when most compilers issue warnings and people online give them grief.Is return 0 really that painful to type???
Why do people use void main?
Started by Coder Zombie, Jan 12 2009 03:14 AM
20 replies to this topic
#1
Posted 12 January 2009 - 03:14 AM
I'm the master of code rot
|
|
|
#2
Guest_Jordan_*
Posted 12 January 2009 - 05:39 AM
Guest_Jordan_*
I'm not sure why people would use it. Apparently programmers are lazy (which isn't always a bad thing). I'm fairly certain return 0 is failure though, you should use EXIT_SUCCESS if your program completes successfully.
#3
Posted 12 January 2009 - 08:01 AM
And who says I'm required to use EXIT_SUCCESS? :-D
I guess viod main -could- be considered easier to explain to noobs, or it could be conservation of vertical text space taken to an extreme. To be honest, I'm not really sure why so many people don't use int main. Being forced to add return 0 is not something I've ever thought of as a bad thing.
I guess viod main -could- be considered easier to explain to noobs, or it could be conservation of vertical text space taken to an extreme. To be honest, I'm not really sure why so many people don't use int main. Being forced to add return 0 is not something I've ever thought of as a bad thing.
Dave
#4
Posted 12 January 2009 - 08:10 AM
As I recall, perhaps incorrectly, void main is OK in C, but not C++. Since many people learn C first, they get into the habit of using void main. It can be a tough habit to break.
#5
Posted 12 January 2009 - 08:12 AM
WingedPanther said:
As I recall, perhaps incorrectly, void main is OK in C, but not C++. Since many people learn C first, they get into the habit of using void main. It can be a tough habit to break.
That makes sense. I learned C++ first, so haven't had too many cases where I was doing something "the C way".
Dave
#6
Posted 12 January 2009 - 08:35 AM
One of my frustrations is some of the C++ books that want to teach you C first. C requires you to perform a number of actions a certain way. Then you have to "unlearn" the C way to use the options that C++ provides. Historically, C++ was meant to be maximally compatible with C to make transitioning from C to C++ as easy as possible, but C++ offers so much more than C, I can't see the value in starting with C-shackles on :)
#7
Posted 12 January 2009 - 09:03 AM
WingedPanther said:
One of my frustrations is some of the C++ books that want to teach you C first. C requires you to perform a number of actions a certain way. Then you have to "unlearn" the C way to use the options that C++ provides. Historically, C++ was meant to be maximally compatible with C to make transitioning from C to C++ as easy as possible, but C++ offers so much more than C, I can't see the value in starting with C-shackles on :)
I guess most tutorial makers don't see it that way. What a lot of people think is that C++ is just C with some extras, not as a different language. C++ is too different from C for people to view it in such a way. Classes alone can make a program look nothing like a C counterpart.
Dave
#8
Posted 12 January 2009 - 09:06 AM
Where I have read, void main is an old standard and not used anymore. So I guess that makes int main superior?
#9
Posted 12 January 2009 - 09:10 AM
Turk4n said:
Where I have read, void main is an old standard and not used anymore. So I guess that makes int main superior?
I guess you could look at it that way. I thought the point of int main was so that the OS had a way to tell if your program had issues. I'm not even sure it really matters anymore these days other than int main is "proper".
Dave
#11
Posted 12 January 2009 - 09:30 AM
v0id said:
Ha ha! I've read that first one before. I must have forgotten.
Dave
#12
Posted 13 January 2009 - 01:18 PM
void main in acceptable. All it basically says is that you take care of all exceptions internally, and nothing gets passed to the function that calls main (forgot the name, I might look it up later). You can end it with ExitProcess(exitCode); if you like, but it's unnecessary. I stand by my motto of "if it's unnecessary, don't include it" in the case of return 0.


Sign In
Create Account


Back to top









