It's time to get that stick out of your butt and start using it. So what if the standard says so? You're only writing code for Windows anyway (and if you aren't, the chances that someone else is even going to need to use your program are really slim) so who cares if you aren't returning anything meaningful? Alright, so maybe a few purists will pop some blood vessels somewhere in their moms' basements, but so what?

"Because I feel like it" is as valid a reason as "because the standard says so".

jephthah commented: scru brings the LOLs. +13

Why doesn't the sun shine at night when we really need it?

Father, forgive him because he knows not what he is doing.

Joking aside, there really is no point to insisting on the use of int main as opposed to void main.

void main()
{
    printf("hello world!\n");
}

is just as valid a program as

int main()
{
    printf("hello world!\n");
    return 0;
}

if you don't sacrifice offerings to the writers of the C standard. That return 0; is wasted effort.

If for some reason an error occurs in your program (real programmers design their programs in such a way that fatal errors never occur) and you need to indicate, that's exactly what stderr is for.

commented: excellent advice! +4

(real programmers design their programs in such a way that fatal errors never occur)

My methodology exactly.

There you go.
You have finally done it.
And all these ^^ don't know about the conspiracy about making some crazy thread.
Oops.........
Yeah sure, void main is my favorite too. ^H^H^H^H^H^H^H^H^H

>>is just as valid a program as
No it isn't because void main() is not allowed by either C or C++ standards. It never was, and never will be. There are compilers that will not allow void main(). The program returns an integer whether you want it to or not.

>>and you need to indicate, that's exactly what stderr is for.
Not really -- if your program is not called by another program then just sending an error message onto the screen might be sufficient. But many programs are launched by other programs -- on *nix machines there is a whole family of spawn functions, and on MS-Windows there is CreateProcess() and several others. Those program often wait for the spawned program to exit and then get its exit status. That will be broken when the spawned program just returns some random value from main().

The tiny programs you write in high school and college are not very significant and more than likely are never spawned by other programs. In those cases it doesn't really matter what you, the programmer, do. After you graduate and start working for software companies you will not be allowed to write programs as you see fit. You will be required to write programs according to company coding standards. Those coding standard will dictate how you code programs and in what format. They mey even tell you how to name variables, functions, c++ classes and a whole host of requirements.

>No it isn't because void main() is not allowed by either C or C++ standards. It
>never was, and never will be. There are compilers that will not allow void main().
>The program returns an integer whether you want it to or not.
I was arguing the same with Narue and found out that this is not true for freestanding environment: http://web.archive.org/web/20050207005628/http://dev.unicals.com/papers/c89-draft.html#2.1.2.1

commented: Great link! :icon_razz: +22

>No it isn't because void main() is not allowed by either C or C++ standards. It
>never was, and never will be. There are compilers that will not allow void main().
>The program returns an integer whether you want it to or not.
I was arguing the same with Narue and found out that this is not true for freestanding environment: http://web.archive.org/web/20050207005628/http://dev.unicals.com/papers/c89-draft.html#2.1.2.1

Those programs are written with embedded compilers, which do not compile with C standards. There are a whole host of exceptions to the standards for compilers that target embedded systems. AFAIK no one here at DaniWeb use such compilers. And here is one such compiler that does not fully conform to C standards, and their web site explains why.

main[] kicks main()'s arse all around yard.

> "Because I feel like it" is as valid a reason as "because the standard says so".
How about "I want my programs to work" vs. "My programs work by magic so long as I use the codemangler 3.0 compiler".

Why stop there?
char *str ; gets(str);
usually had a pretty good chance of success, for DOS programmers.
Does that make them good, or just lucky?

Something else you might want to consider.
If you thought learning C was hard the first time around, just try unlearning a bunch of crap C because you new codescribbler 4.2 compiler complains about all sorts of things, and the OS just lays your program out cold whenever it touches an illegal pointer.

Do you?
a) re-learn a bunch of compiler specific tricks for each new compiler.
b) learn ANSI-C and stop worrying about when the next incompatibility is gonna bits your ass.

I did "a" exactly once, and it sucked!

Oh, and it's not just hypothetical waffle.
http://users.aber.ac.uk/auj/voidmain.shtml
At least one REAL machine barfs on void main.

Do you think all this internet stuff works because
a) everyone followed the standards
b) everyone did their own thing which "worked for me" in their own little corner of the universe.

Or how about two banks transferring money. Bank A sends it in hex, and bank B receives it in decimal, do you
a) congratulate the programmers on their sense of individualism
b) hammer down the doors screaming "where's my **** money!?"

commented: lol, Good stuff. +6
commented: Man you're a killjoy! -1
commented: We have a winner! +21

everyone did their own thing which "worked for me" in their own little corner of the universe.

but, but... Microsoft did it!

DOS has all the hallmarks of a "there are no rules" embedded system.
- limited memory
- no memory protection
- limited interrupt capability
- poor device support
- only able to run one program at once without resorting to hacks.

So it appears I have already pissed off a purist.

I'm not bashing standards all together, but doing something for the sake of the standard where it saves me a bit of effort to do it in another way that works just as well is retarded. So what if some arbitrary machine somewhere in space won't run my code? And yes jephthah, Microsoft did it. Look at how many non-standard things Microsoft does and gets away with. I deserve some of that action too.

Everyone should use void main if only to be daring.

My mistake, this is a joke thread after all - carry on.

i think he's only half joking.

which means he's half-serious.

which means you'll never pin him down long enough to get the win.

half joking + half serious = complete ass

Spoon boy: Do not try and correct void main. That's impossible. Instead... only try to realize the truth.
Neo: What truth?
Spoon boy: There is no void main.
Neo: There is no void main?
Spoon boy: Then you'll see, that it is not the void main what you correct, it is only yourself.

half joking + half serious = wholly awesome

I fixed that for you.

> I fixed that for you.

You shouldn't, really. You just proved his point. :-)

commented: Heh, and jephthah thought that it couldn't be done. +36
commented: Good one :P +16

... but doing something for the sake of the standard where it saves me a bit of effort to do it in another way that works just as well is retarded.

Makes sense. Let's use this attitude elsewhere in life. Gee, stopping for that red light ahead is just an arbitrary rule some committee came up with. Going through the light in and of itself won't be a problem, the light can't hurt, and I won't have to step on the brake. Stepping on the brake for the sake of a light is retarded.

And yes jephthah, Microsoft did it. Look at how many non-standard things Microsoft does and gets away with.

And look how many fixes they have to make every month because they cut corners and don't follow standards. Can you name another major OS that crashes as often as Windows? Maybe int main() does make a difference you're unaware of....

well, i'm no microsoft fanboi, and i hate Vista as much as the next guy (I'm using a linux distro as i type), and i do get the point you're trying to make...

... but i seriously doubt that any of microsoft's myriad of problems have to do with void main()

> but i seriously doubt that any of microsoft's myriad of problems
> have to do with void main()

Yeah, it's gotta be the way they think which makes them use void main(). :-)

commented: They think??? That's news! +21
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.