Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > 2 very basic qns

Reply
Thread Tools

2 very basic qns

 
 
mescaline
Guest
Posts: n/a
 
      12-29-2003
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
 
Reply With Quote
 
 
 
 
Ron Natalie
Guest
Posts: n/a
 
      12-29-2003

"mescaline" <(E-Mail Removed)> wrote in message news:(E-Mail Removed) om...
> 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.

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


 
Reply With Quote
 
 
 
 
Gary Labowitz
Guest
Posts: n/a
 
      12-29-2003
"Ron Natalie" <(E-Mail Removed)> wrote in message
news:3fef4a9c$0$31832$(E-Mail Removed) m...
>
> "mescaline" <(E-Mail Removed)> wrote in message

news:(E-Mail Removed) om...
> > 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


 
Reply With Quote
 
Ron Natalie
Guest
Posts: n/a
 
      12-29-2003

"Gary Labowitz" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> 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.

 
Reply With Quote
 
mescaline
Guest
Posts: n/a
 
      12-29-2003
"Gary Labowitz" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> "Ron Natalie" <(E-Mail Removed)> wrote in message
> news:3fef4a9c$0$31832$(E-Mail Removed) m...
> >
> > "mescaline" <(E-Mail Removed)> wrote in message

> news:(E-Mail Removed) om...
> > > 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
 
Reply With Quote
 
Ron Natalie
Guest
Posts: n/a
 
      12-29-2003

"mescaline" <(E-Mail Removed)> wrote in message news:(E-Mail Removed) om...
>> 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.

 
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
Qns on blank lines eight02645999@yahoo.com Python 0 03-03-2006 07:06 AM
T'Bird Address Book Qns Dennis J. Tuchler Firefox 3 07-28-2005 12:24 AM
Very very very basic question Peter C Programming 14 02-14-2005 09:46 AM
2 Qns re Thunderbird Dennis J. Tuchler Firefox 7 12-23-2004 10:26 PM
Misc Qns... Jin C Programming 20 12-25-2003 01:45 AM



Advertisments