Advertisement

whats the point of -> void main();

Started by November 22, 2000 11:40 AM
24 comments, last by Tsu 24 years, 1 month ago
whats the point of putting something like: void main()... i see books have it all the time, but what does it mean / do??? _________
Tsutomegi
Because you don''t want it to return an int. That violates the ANSI standard though.

Advertisement
do i need it?
so basically, its the type of var returned or something???

_________
Tsutomegi
always write int main; void main() can cause very hard to track down errors, and if you cant spare 5 seconds to type out return 0; then you deserve to spend weeks debuging this.

-----------------------------

A wise man once said "A person with half a clue is more dangerous than a person with or without one."

The Micro$haft BSOD T-Shirt
-----------------------------A wise man once said "A person with half a clue is more dangerous than a person with or without one."The Micro$haft BSOD T-Shirt
ImmaGNUman, what kind of errors does void main() cause? I''ve always used void main() and I''ve never had any strange errors that I couldn''t figure out.


- Houdini
- Houdini
The return value of your program (main) can be used in batch files or whatever to check if it succeeded (errorlevel)
Advertisement
Yeah, I had a quesion about that. I used to use void but now I always use int cuz everyone does But anyway, I return(0) at the end. Wow. What exactly did I return it to? Get my meaning? In other words, how do I check if that function actually ran or whatever return(0) is supposed do?

thanks,

peon
Peon
The return value is always given back to the OS. When you return 0 it means, your program has run successfully. Whenever a critical error occurs (with critical I mean, you can''t continue the program because of the error, eg: the primary surface could not be created), you should catch that and print some message or something and do exit(1). This will return 1 instead of the 0.

Well, I guess it is something like that...

And int main() is the ANSI standard which means that it is possible that some compilers won''t be happy with void main() . In other words: always use int main().
Actually the latest ANSI standard says that compilers HAVE to accept void main(). Personally I prefer using int main() but that is so I can return a value to the OS.

Dire Wolf
direwolf@digitalfiends.com

Edited by - Dire.Wolf on November 24, 2000 1:31:33 AM
[email=direwolf@digitalfiends.com]Dire Wolf[/email]
www.digitalfiends.com
ANSI Sec 5.2.2.1:
"[main] shall be defined with a return type of int."

This topic is closed to new replies.

Advertisement