void main

H

Howard

Hi all,

with all the posts I see that have "void main()", and all the resulting
corrections, I have to wonder...is there a commonly-used IDE out there that
generates "void main()" by default when creating a new project? Or is this
a practice taught in schools? Or...? (Just curious as to why it's so
common.)

-Howard
 
P

Phlip

Howard said:
with all the posts I see that have "void main()", and all the resulting
corrections, I have to wonder...is there a commonly-used IDE out there that
generates "void main()" by default when creating a new project? Or is this
a practice taught in schools? Or...? (Just curious as to why it's so
common.)

Visual C++, from Microsoft's Visual Studio, creates the correct return value
for both main(), _tmain(), and all the Microsoft-specific alternatives.

However, a majority of MS's sample code, and sample code from their vassal
states, uses 'void main', just as it uses 300 line functions, redundant
typecasts, downcasts, rampant code duplication, pointers that could have
been references, etc.

This sample code's intent is to lead programmers to use MS tools in the most
sloppy and fragile way. If programmers cannot easily port code to another
compiler, then they cannot "jump ship" and reposition their offerings to
target other platforms.

This newsgroup does much work to reaffirm programmers' independence from
their vendor's sloppy sample code. But that work devolves when you read all
the screaming admonitions against 'void main'.

'void main' also appears in embedded code situations, where 'main()' might
compile into the actual startup address for a chip. A return value from such
a 'main()' cannot "go anywhere", because no software environment hosts such
a program. This is still not an excuse to write 'void main'.
 
J

JKop

Howard posted:
Hi all,

with all the posts I see that have "void main()", and all the
resulting
corrections, I have to wonder...is there a commonly-used IDE out there
that generates "void main()" by default when creating a new project?
Or is this a practice taught in schools? Or...? (Just curious as to
why it's so common.)

-Howard

Well when I started out I was thinking "I don't give a poo what my program
returns", so the first thing I tried was:

void main()
{

}


but that's not allowed, it has to be:

int main()
{

}


But the good thing is that don't have to write a return statement in main!

-JKop
 
C

Chris Theis

Howard said:
Hi all,

with all the posts I see that have "void main()", and all the resulting
corrections, I have to wonder...is there a commonly-used IDE out there that
generates "void main()" by default when creating a new project? Or is this
a practice taught in schools? Or...? (Just curious as to why it's so
common.)

Unfortunately I´ve seen it a lot to be a practice taught in schools and also
at Universities (even CS departments!).

Chris
 
A

Alex Trueman

Chris said:
Unfortunately I´ve seen it a lot to be a practice taught in schools and also
at Universities (even CS departments!).

Chris
Why is it wrong? Is it just bad style or is there a fundamental problem with it?
 
J

JKop

Alex Trueman posted:
Why is it wrong? Is it just bad style or is there a fundamental problem
with it?


Think of how "I didn't went to the town centre", and then add a compile
error to that.
 
R

Robert Bauck Hamar

* Alex Trueman said:
Why is it wrong? Is it just bad style or is there a fundamental problem with it?

Because the standard says that main _shall_ return int.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,175
Messages
2,570,942
Members
47,476
Latest member
blackwatermelon

Latest Threads

Top