PDA

View Full Version : How evil is void main?



Hunter2
11-28-2002, 11:18 AM
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^

biosninja
11-28-2002, 11:27 AM
NOOOO - EVIL!!!!!! evil I say!!!!

CodeMonkey666
11-28-2002, 11:43 AM
What's wrong with void main()?

XSquared
11-28-2002, 11:45 AM
CodeMonkey666, Prelude's gonna kill you.

-Xp-
11-28-2002, 12:00 PM
lol it wont DESTROY me, it will make me miserable though

int main {} :P

biosninja
11-28-2002, 12:02 PM
CodeMonkey666, Prelude's gonna kill you.

Not if one of the others get to him first:p

valar_king
11-28-2002, 12:10 PM
Everybody needs to quit complaining* about void main(), if someone else wants to use it, let them, as long as you don't have to work with their code.


*Editted for content by Kermi3

kevinalm
11-28-2002, 01:12 PM
Void main isn't evil, it's just wrong. Anyway, any decent modern compiler ignors void main() and makes it int main() behind your back.

biosninja
11-28-2002, 01:20 PM
Void main isn't evil, it's just wrong

Evil = Wrong:D


any decent modern compiler ignors void main() and makes it int main() behind your back.

What compiler u using?

kevinalm
11-28-2002, 01:46 PM
>>Evil = Wrong
If you want to define evil that way, I won't argue.

Usually gcc under Linux. Most modern compilers that will accept void main() actually compile it as int main(), they just doesn't tell you that's what they're doing. Myself, I always use int main().

biosninja
11-28-2002, 02:00 PM
If you want to define evil that way, I won't argue

That's one of the evil things I know, (void main) not defining it.;)


Myself, I always use int main().

Same here. when I started C++ and use *ahem* "void main", my instructor almost beat the living crap out of me.:D

Cgawd
11-28-2002, 03:07 PM
if youre a sloppy programmer, feel free to void main, but if you are professional and want to program properly, int main....bottom line. It all comes down to good habits. Just like smoking is a bad habit, sure at first it feels good and stuff, but eventually IT WILL KILL YOU.

Magos
11-28-2002, 03:24 PM
Correct me if I'm wrong, but when declaring main to return an int you can decide which exit code is returned. When declaring main to return a void (nothing) the exit code is predefined (ie: 0).

http://msdn.microsoft.com./library/default.asp?url=/library/en-us/vclang98/HTML/_pluslang_program_startup.3a_.the_main_function.as p

biosninja
11-28-2002, 03:37 PM
Correct me if I'm wrong, but when declaring main to return an int you can decide which exit code is returned. When declaring main to return a void (nothing) the exit code is predefined (ie: 0).


True. 0 is the code for "a normal exit" - no errors

Magos
11-28-2002, 03:46 PM
Then what's so evil about it? Ok, you cannot specify an error return code if your program fails to do some stuff, but that seems kinda minor to me...

(I still use int main, so don't accuse me to be a voider :D)

biosninja
11-28-2002, 03:52 PM
(I still use int main, so don't accuse me to be a voider )

Well, as long as your not one of them voiders!!! :D

valar_king
11-28-2002, 03:58 PM
I, also, use int main(), but void main() doesnt seem too bad to me

ygfperson
11-28-2002, 04:02 PM
Originally posted by Magos
Then what's so evil about it? Ok, you cannot specify an error return code if your program fails to do some stuff, but that seems kinda minor to me...

(I still use int main, so don't accuse me to be a voider :D)
microsoft may define the return value of a void main function as zero, but that's not a standard consensus. other compilers simply ignore the return value, which may cause your operating system to suspect a problem.

biosninja
11-28-2002, 04:03 PM
void main() doesnt seem too bad to me


NOOOOO!!!! Stay away from the light!!!!

*Looks in fear over shoulder for Prelude *

ammar
11-28-2002, 04:25 PM
I always ask myself, if they say that int main() is the standart way, why don't we just stick to it?
And why are all these threads about int/void main().
Using void main() won't make our lifr easier.

Note: I think in the FAQ's there is a section about that.

By The Way, check out Salem's avatar, they are doomed:)

abrege
11-28-2002, 04:58 PM
void main()
void main()
void main()
void main()

Wheee void main() rocks!!

minesweeper
11-28-2002, 05:19 PM
Oh my goodness. Prelude is gonna go ballistic. We have all seen her let off steam before about void main(). Now we have a thread created solely for the purpose of debating the issue. Dig yourselves a trench fellas and take cover, this could be messy!!

biosninja
11-28-2002, 05:32 PM
Oh my goodness. Prelude is gonna go ballistic

Yeah...Tell me about it

Salem
11-28-2002, 05:44 PM
You can either choose to do the right thing, and try to learn as much about the language as possible so that your programs have the most chance of working because you've learnt ANSI-C. This approach will stand you in good stead for when you have to use a new compiler (or even the next version of the one you're using now).

Or you can choose to riddle your programs with all sorts of undefined behaviour because you've learn dialect-C, and so long as it "works for me" that's OK right. This approach will really bite you in the ass in the long run and you find that you have to unlearn all your bad habits (you must unlearn what you have learnt if you are to learn the ways of the source) when you have to move to a new environment. If you are fortunate, you will decide to make a much better job of learning the language the 2nd time around.

If you are wise, you'll make sure you try and make a decent job of it the first time round.

So if you want to keep all your small programs private, compile them once and throw them away after they've served their immediate purpose then go ahead use all the undefined behaviour you want - its only your time you're wasting, and the rest of the world can go about its business.

But if you want to write a large program, or work with other peoples code (and have others work with yours), and you want to avoid your fellow programmers wrath / humor / distrust, then you'll want to seek out and remove as much undefined behaviour from your programs as you can, and learn the language properly so that you don't add undefined behaviour as a matter of habit in the first place.

Remember, void main could say a lot more about the rest of your code than you would care to admit.

http://www.cprogramming.com/cboard/showthread.php?s=&threadid=29141
http://www.cprogramming.com/cboard/showthread.php?s=&threadid=28633
http://www.cprogramming.com/cboard/showthread.php?s=&threadid=28311
http://www.eskimo.com/~scs/C-faq/q11.15.html
http://www.eskimo.com/~scs/C-faq/q11.12.html

And just for those void main'ers who cling to - nobody looks at the exit status
http://www.eskimo.com/~scs/C-faq/q11.14.html

Fountain
11-28-2002, 05:56 PM
(you must unlearn what you have learnt if you are to learn the ways of the source)

Thats funny.

:)

Hammer
11-28-2002, 05:59 PM
I think we've had enough void/int main conversations for now. If you haven't worked out what is correct by reading this thread, do a seach to find out more.

Now please.... no more! :)

<closed: any questions, pm me.>