C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

2 very basic qns

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
mescaline
Guest





PostPosted: Mon Dec 29, 2003 2:23 am    Post subject: 2 very basic qns Reply with quote



1. Why does C++ require the int in:
int main(){...}
(is there a special reason for int, why not void,etc...?)

2. What purpose does the return 0; serve at the end of the main
program:
(when the program is run successfully and the " return 0; " statement
is encountered, what exactly happens -- where is the 0 returned?)

thanks
Back to top
Ron Natalie
Guest





PostPosted: Mon Dec 29, 2003 2:31 am    Post subject: Re: 2 very basic qns Reply with quote




"mescaline" <apt2003 (AT) columbia (DOT) edu> wrote

Quote:
1. Why does C++ require the int in:
int main(){...}
(is there a special reason for int, why not void,etc...?)

Are you talking about main specifically or functions in general. The "implicit"
int return has been removed from the language because it wasn't exactly consistant.

As far as why MAIN itself must return int. Tradition is the major reason.

Quote:

2. What purpose does the return 0; serve at the end of the main
program:
(when the program is run successfully and the " return 0; " statement
is encountered, what exactly happens -- where is the 0 returned?)

It's an implementation specific success code. On some systems it gets

passed back to the invoked program (like UNIX). On some systems
the environment calls a system call indicating normal termination where as
the error returns from exit/main call the error system call. On others a
zero means silent exit while a non-zero return cause an error popup.
Others the value is just discarded.



Back to top
Gary Labowitz
Guest





PostPosted: Mon Dec 29, 2003 5:59 am    Post subject: Re: 2 very basic qns Reply with quote



"Ron Natalie" <ron (AT) sensor (DOT) com> wrote

Quote:

"mescaline" <apt2003 (AT) columbia (DOT) edu> wrote

1. Why does C++ require the int in:
int main(){...}
(is there a special reason for int, why not void,etc...?)

Are you talking about main specifically or functions in general. The
"implicit"
int return has been removed from the language because it wasn't exactly
consistant.

As far as why MAIN itself must return int. Tradition is the major
reason.


Well, not really. The standards group, that works on defining the language,
has published a standard that main must return an int.
Unless you want to call standards a tradition...
--
Gary



Back to top
Ron Natalie
Guest





PostPosted: Mon Dec 29, 2003 1:01 pm    Post subject: Re: 2 very basic qns Reply with quote


"Gary Labowitz" <glabowitz (AT) comcast (DOT) net> wrote

Quote:
Well, not really. The standards group, that works on defining the language,
has published a standard that main must return an int.
Unless you want to call standards a tradition...
--
I know that. The poster asked for WHY. The language is defined by the

standard, but the standards people had reasons for the requirements they
set down. The reason main is REQUIRED BY THE STANDARD
to return in is TRADITION. Main has always returned int, ever since
the early days of C. Partially this was because C didn't even have a void
type in the beginning, then later because UNIX relied heavily on using the
numeric return from programs.


Back to top
mescaline
Guest





PostPosted: Mon Dec 29, 2003 2:23 pm    Post subject: Re: 2 very basic qns Reply with quote

"Gary Labowitz" <glabowitz (AT) comcast (DOT) net> wrote

Quote:
"Ron Natalie" <ron (AT) sensor (DOT) com> wrote in message
news:3fef4a9c$0$31832$9a6e19ea (AT) news (DOT) newshosting.com...

"mescaline" <apt2003 (AT) columbia (DOT) edu> wrote in message
news:e54f0744.0312281823.2db5f4b2 (AT) posting (DOT) google.com...
1. Why does C++ require the int in:
int main(){...}
(is there a special reason for int, why not void,etc...?)

Are you talking about main specifically or functions in general. The
"implicit"
int return has been removed from the language because it wasn't exactly
consistant.

As far as why MAIN itself must return int. Tradition is the major
reason.

Well, not really. The standards group, that works on defining the language,
has published a standard that main must return an int.
Unless you want to call standards a tradition...


Conversely, does it always return a non-zero value, when there's *any*
error with the compiling?

thanks

Back to top
Ron Natalie
Guest





PostPosted: Mon Dec 29, 2003 2:51 pm    Post subject: Re: 2 very basic qns Reply with quote


"mescaline" <apt2003 (AT) columbia (DOT) edu> wrote

Quote:
Conversely, does it always return a non-zero value, when there's *any*
error with the compiling?


If you had problems compiling, you're not likely going to get as far as
having a main function to run.


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.