 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
mescaline Guest
|
Posted: Mon Dec 29, 2003 2:23 am Post subject: 2 very basic qns |
|
|
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
|
Posted: Mon Dec 29, 2003 2:31 am Post subject: Re: 2 very basic qns |
|
|
"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
|
Posted: Mon Dec 29, 2003 5:59 am Post subject: Re: 2 very basic qns |
|
|
"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
|
Posted: Mon Dec 29, 2003 1:01 pm Post subject: Re: 2 very basic qns |
|
|
"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
|
Posted: Mon Dec 29, 2003 2:23 pm Post subject: Re: 2 very basic qns |
|
|
"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
|
Posted: Mon Dec 29, 2003 2:51 pm Post subject: Re: 2 very basic qns |
|
|
"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 |
|
 |
|
|
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
|
|