PDA

View Full Version : void main



Shadow
05-28-2002, 11:48 PM
Ah yes, the infamous discussion.
Ignore this thread if you wish, I just thought I'd post my thoughts which got me thinking on the topic.

int main()
7 letters
return 0;
6 letters and a number, 7 keys

A total of 14 characters for int main / return 0.

void main()
8 letters
return;
6 letters

A total of 14 characters.

int main()
7 again - not returning anything ( small program )

void main
8 again - not returning anything ( small program )

It actually isn't harder to say int main, it's equal when returning something, and easier when not. It's also safer.

Void main, is truly wrong.

Vicious
05-28-2002, 11:52 PM
I have never and never will use void main()...

I have a habbit of typing this as soon as I start a project



#include <iostream.h>

int main()
{

cin.get();
return 0;
}


Sometimes... I wake up and my fingers are typing this out on my mattress...:(

tim545666
05-29-2002, 12:00 AM
Your logic is off. I was taught that int main was the same as void main. I don't use void main anymore, but when I did, I never put a return statement. Return isn't necessary with void main.

Shadow
05-29-2002, 12:05 AM
> Return isn't necessary with void main.
And a program is not needed unless it returns something.

A simple example:
I created a menu program for a fair amount of dos based classic pc games. I would check how the execution went, and display more user friendly messages if something went wrong. Because one of the games were programmed by void main programmers, I couldn't detect this. So not only were they not included into my menu for choices, but they also got deleted off my hard drive for the trouble.

[ / End slam of ID software's early days ]

SilentStrike
05-29-2002, 12:21 AM
Should make that..

#include <iostream.h>

into

#include <iostream>

For the same reason as not having void main.. it's non-standard.

nvoigt
05-29-2002, 12:54 AM
>I was taught that int main was the same as void main.

Which is simply wrong. There are two forms of main defined in the standard:

int main()
int main( int argc, char* argv[] )

Everything else is wrong. Your compiler may accept it, and build a workaround internally, but that doesn't mean it's correct. It's like running a red light at night. Probably safe, but still you shouldn't do it.

toaster
05-29-2002, 01:07 AM
what about compilers that require you to prototype or declare or initialize ecetra the main(argument(s))?



//sample

#include<stdio.h>
using namespace std;

int main(int argc, char *argv[]);

int main(int argc, char *argv[])
{
printf("this is what you are running: %s", argv[0]);
// code
return 0;
}

Salem
05-29-2002, 10:58 AM
> what about compilers that require you to prototype
Which compiler needs this?

You shouldn't need to do this

ygfperson
05-29-2002, 12:53 PM
Originally posted by Shadow
Void main, is truly wrong.
whoa...

Vicious
05-29-2002, 03:15 PM
I cant use

#include <iostream>

cause Borland will not accept

using namespace std;

it has an error that says namespace expected

Dual-Catfish
05-29-2002, 04:11 PM
int main()
7 letters
return 0;
6 letters and a number, 7 keys

A total of 14 characters for int main / return 0.

void main()
8 letters
return;
6 letters

A total of 14 characters.

It'd be nice if you were consistant..

int main()
9 keypresses
return 0;
9 keypresses

void main()
11 keypresses
return;
7 keypresses

That's 18 and 18!

ygfperson
05-29-2002, 05:51 PM
you forgot the enter key...

SilentStrike
05-29-2002, 05:57 PM
Ouch.. a compiler that doesn't accept namespaces? Honestly, I think it's time to upgrade.

Hammer
05-29-2002, 06:02 PM
Originally posted by ygfperson
you forgot the enter key...
And the shift key :)

-KEN-
05-29-2002, 06:11 PM
But sum d00d who sed he was a VB MASTRE tlod me taht void main() was rite and all the ****ers who say itn main() is right r jsut P0S3R5 who should bow 2 our 1337nes@!

Shadow
05-29-2002, 07:08 PM
> And the shift key
> Ouch.. a compiler that doesn't accept namespaces? Honestly, I think it's time to upgrade.
> you forgot the enter key...
Now now.. :p