Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: Big Deal with returning int

Reply
Thread Tools

Re: Big Deal with returning int

 
 
John Harrison
Guest
Posts: n/a
 
      06-29-2003

"Klaus Eichner" <(E-Mail Removed)> wrote in message
news:3efea6fa$0$12457$(E-Mail Removed)...
> "Min" <(E-Mail Removed)> wrote in message
> news:VgvLa.341602$(E-Mail Removed) a...
> > I have seen so many pointing out "main" should explicitly return "int".
> > Beside, the language spec or committee, or some guru said so, what is a

> BIG
> > deal with it ? What difference does it make if "void main" rather than

> "int
> > main" ? It is not that some obscure code that people can't understand
> > easily. Anyway, would someone explain why ;? not just it is better to
> > return explicitly.

>
> http://www.research.att.com/~bs/bs_faq2.html#void-main


Well that provides a good explaination of what the situation is and from the
horse's mouth, so to speak. But it still doesn't explain why. I'm still
contending that there is no good explaination.

john


 
Reply With Quote
 
 
 
 
Klaus Eichner
Guest
Posts: n/a
 
      06-29-2003
"Min" <(E-Mail Removed)> wrote in message
news:VgvLa.341602$(E-Mail Removed) a...
> I have seen so many pointing out "main" should explicitly return "int".
> Beside, the language spec or committee, or some guru said so, what is a

BIG
> deal with it ? What difference does it make if "void main" rather than

"int
> main" ? It is not that some obscure code that people can't understand
> easily. Anyway, would someone explain why ;? not just it is better to
> return explicitly.


http://www.research.att.com/~bs/bs_faq2.html#void-main

> Or How is it possibly cause the problem ?
>
> PS: I am saying this because most of C++ books I found, uses "void main".
> If they can't get this fundamental thing right, I guess, I have been

reading
> all the garbage from them.



 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      06-29-2003
> > >
> > > http://www.research.att.com/~bs/bs_faq2.html#void-main

> >
> > Well that provides a good explaination of what the situation is and from

> the
> > horse's mouth, so to speak. But it still doesn't explain why. I'm still
> > contending that there is no good explaination.

>
> I don't think there is a conclusive explanation in the standard,


I wouldn't expect it to be there.

> neither do
> I believe that such an explanation is necessary.


Not necessary perhaps, but it would be nice to know.

> There is, however, a lot of
> discussion out there, especially in comp.std.c++. See, for example, the
> discussion started by Huw Ford, Subject: Why int main()?Newsgroups:
> comp.std.c++, date: 2003-04-11 02:52:13 PST


Thanks, I'll take a look.

john


 
Reply With Quote
 
John Harrison
Guest
Posts: n/a
 
      06-29-2003
>
> > There is, however, a lot of
> > discussion out there, especially in comp.std.c++. See, for example, the
> > discussion started by Huw Ford, Subject: Why int main()?Newsgroups:
> > comp.std.c++, date: 2003-04-11 02:52:13 PST

>
> Thanks, I'll take a look.
>
> john


Seems to me the reason is probably to do with the historical development of
C and C++ (in particular the later introduction of void to C and the banning
of implicit int return in C++). So no good objective reason just historical
accident, which is fair enough.

john


 
Reply With Quote
 
Klaus Eichner
Guest
Posts: n/a
 
      06-29-2003
"John Harrison" <(E-Mail Removed)> wrote in message
news:bdm98j$u6agh$(E-Mail Removed)...
>
> "Klaus Eichner" <(E-Mail Removed)> wrote in message
> news:3efea6fa$0$12457$(E-Mail Removed)...
> > "Min" <(E-Mail Removed)> wrote in message
> > news:VgvLa.341602$(E-Mail Removed) a...
> > > I have seen so many pointing out "main" should explicitly return

"int".
> > > Beside, the language spec or committee, or some guru said so, what is

a
> > BIG
> > > deal with it ? What difference does it make if "void main" rather

than
> > "int
> > > main" ? It is not that some obscure code that people can't understand
> > > easily. Anyway, would someone explain why ;? not just it is better to
> > > return explicitly.

> >
> > http://www.research.att.com/~bs/bs_faq2.html#void-main

>
> Well that provides a good explaination of what the situation is and from

the
> horse's mouth, so to speak. But it still doesn't explain why. I'm still
> contending that there is no good explaination.


I don't think there is a conclusive explanation in the standard, neither do
I believe that such an explanation is necessary. There is, however, a lot of
discussion out there, especially in comp.std.c++. See, for example, the
discussion started by Huw Ford, Subject: Why int main()?Newsgroups:
comp.std.c++, date: 2003-04-11 02:52:13 PST
http://tinyurl.com/fjww

> john
>
>



 
Reply With Quote
 
Karl Heinz Buchegger
Guest
Posts: n/a
 
      06-30-2003


John Harrison wrote:
>
> "Klaus Eichner" <(E-Mail Removed)> wrote in message
> news:3efea6fa$0$12457$(E-Mail Removed)...
> > "Min" <(E-Mail Removed)> wrote in message
> > news:VgvLa.341602$(E-Mail Removed) a...
> > > I have seen so many pointing out "main" should explicitly return "int".
> > > Beside, the language spec or committee, or some guru said so, what is a

> > BIG
> > > deal with it ? What difference does it make if "void main" rather than

> > "int
> > > main" ? It is not that some obscure code that people can't understand
> > > easily. Anyway, would someone explain why ;? not just it is better to
> > > return explicitly.

> >
> > http://www.research.att.com/~bs/bs_faq2.html#void-main

>
> Well that provides a good explaination of what the situation is and from the
> horse's mouth, so to speak. But it still doesn't explain why.


Because in C and C++ it is defined to be that way. And it is that way because
one needs to have a way to inform the 'caller' of that function of certain
conditions. This is done with the help of the return type.

It is similar to:

int foo()
{
return 0;
}

int foo2()
{
int i;

i = foo();
}

foo returns an int and thus informs foo2 of certain things. Now if you decide
that foo no longer has some meaningfull return value, you change it to:

void foo()
{
}

int foo2()
{
int i;

i = foo();
}

But now you have a problem: you can't no longer use the return value of foo
for the assignment in foo2()! foo no longer returns anything! You have to change
foo2() too! So changing parameter passing mechanisms and return values allways
affects 2 sides: the caller and the callee.

Well. The exact analog situation is with main and the operating system. Your
main function equals foo(). And the operating system equals foo2(). If you
change the return type of foo() (your main()) you also have to change
the callers code. But hey! The callers code is out of your control! You
cannot change the way main is called from the OP. And the callers code
expects your main function to return an int! This is how it has been
defined years back!

--
Karl Heinz Buchegger
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Big Deal with returning int Kelsey Bjarnason C++ 38 07-01-2003 10:24 PM
Re: Big Deal with returning int Jonathan Clements C++ 7 07-01-2003 04:42 PM
Re: Big Deal with returning int Samuele Armondi C++ 0 06-29-2003 04:21 PM
Re: Big Deal with returning int Rolf Magnus C++ 0 06-29-2003 11:47 AM
Re: Big Deal with returning int Ian C++ 0 06-29-2003 07:29 AM



Advertisments