1

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".

Votes + Comments
scru brings the LOLs.
10
Contributors
22
Replies
23
Views
8 Years
Discussion Span
Last Post by ~s.o.s~
Featured Replies
  • 1
    scru 909   8 Years Ago

    Joking aside, there really is no point to insisting on the use of int main as opposed to void main. [code=c] void main() { printf("hello world!\n"); } [/code] is just as valid a program as [code=c] int main() { printf("hello world!\n"); return 0; } [/code] if you don't sacrifice offerings … Read More

  • 1

    >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 … Read More

  • 1

    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. Read More

  • 1

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

  • 2
    ~s.o.s~ 2,560   8 Years Ago

    > I fixed that for you. You shouldn't, really. You just proved his point. :-) Read More

1

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.

Votes + Comments
excellent advice!
0

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

My methodology exactly.

0

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

0

>>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.

1

>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

Votes + Comments
Great link! :icon_razz:
0

>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.

1

> "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!?"

Votes + Comments
We have a winner!
Man you're a killjoy!
lol, Good stuff.
0

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

but, but... Microsoft did it!

0

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.

0

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.

1

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.

1

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.

0

half joking + half serious = wholly awesome

I fixed that for you.

2

> I fixed that for you.

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

Votes + Comments
Good one :P
Heh, and jephthah thought that it couldn't be done.
0

... 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....

0

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()

1

> 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(). :-)

Votes + Comments
They think??? That's news!
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.