473,385 Members | 1,324 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

C89/C90: Returning 0 from main()

Hi,

What does returning 0 from main() mean according to C89/C90 standard?
I've found that in C99 it means successful termination (7.20.4.3p5)
however as I'm editing book on C at Polish Wikibooks I'd like to know
what C89/C90 says about it - quotation from C89 or C90 would be nice.

Moreover, in C99 main() function is somewhat special because lack of
return statement is equivalent with returning zero (5.1.2.2.3p1). Is
it also the case in C89/C90?

BTW. Is there any publicly available (draft of) C89/C90 standard?

--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86*tlen.pl>---<jid:mina86*chrome.pl>--ooO--(_)--Ooo--
Feb 13 '07 #1
8 2724
On Feb 13, 1:57 pm, Michal Nazarewicz <min...@tlen.plwrote:
Hi,

What does returning 0 from main() mean according to C89/C90 standard?
I've found that in C99 it means successful termination (7.20.4.3p5)
however as I'm editing book on C at Polish Wikibooks I'd like to know
what C89/C90 says about it - quotation from C89 or C90 would be nice.
First, the main() quote:
"A return from the initial call to the main function is equivalent to
calling the exit function with the value returned by the main function
as its argument. If the main function executes a return that specifies
no value, the termination status returned to the host environment is
undefined."
Return statement:
"Reaching the } that terminates a function is equivalent to executing
a return statement without an expression."
exit() function:
"Finally, control is returned to the host environment. If the value of
status is zero or EXIT_SUCCESS , an implementation-defined form of the
status successful termination is returned. If the value of status is
EXIT_FAILURE , an implementation-defined form of the status
unsuccessful termination is returned. Otherwise the status returned is
implementation-defined."
Moreover, in C99 main() function is somewhat special because lack of
return statement is equivalent with returning zero (5.1.2.2.3p1). Is
it also the case in C89/C90?
It doesn't seem to be with regards to the quoted material, but someone
else should confirm this.
BTW. Is there any publicly available (draft of) C89/C90 standard?
It's available at http://web.archive.org/web/20050207005628/http://
dev.unicals.com/papers/c89-draft.html.
--
WYCIWYG - what you C is what you get

Feb 13 '07 #2
Michal Nazarewicz <mi****@tlen.plwrote:
What does returning 0 from main() mean according to C89/C90 standard?
From n869 [1]:

5.1.2.2.3: "If the return type of the main function is a type compatible
with int, a return from the initial call to the main function is
equivalent to calling the exit function with the value returned by the
main function as its argument;"

7.20.4.3 (The exit function), subparagraph 5: "If the value of status
is zero or EXIT_SUCCESS, an implementation-defined form of the status
successful termination is returned."
Moreover, in C99 main() function is somewhat special because lack of
return statement is equivalent with returning zero (5.1.2.2.3p1). Is
it also the case in C89/C90?
No; in C89, omission of the return statement causes an unspecified
termination status to be returned from the host environment (I will
leave quoting the relevant portion of the standard to someone with
more time to look it up).
BTW. Is there any publicly available (draft of) C89/C90 standard?
[1] I apparently have been laboring under the delusion that n869 was a
draft of the C89 Standard; a look at the foreward of that document
reveals that it is not so. I also thought the FAQ addressed this
question, but I don't see that either. I've started my morning 0/2
and mostly failed to be helpful; sorry about that.

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Feb 13 '07 #3
Christopher Benson-Manica <at***@otaku.freeshell.orgwrote:
No; in C89, omission of the return statement causes an unspecified
termination status to be returned from the host environment (I will
D'oh - of course, that should be "TO the host environment". Perhaps I
should forego attempting to work today, or at least head back to
Starbucks.

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Feb 13 '07 #4
Michal Nazarewicz wrote:
Hi,

What does returning 0 from main() mean according to C89/C90 standard?
I've found that in C99 it means successful termination (7.20.4.3p5)
however as I'm editing book on C at Polish Wikibooks I'd like to know
what C89/C90 says about it - quotation from C89 or C90 would be nice.
The same verbiage you referred to is found in C89 at 7.10.4.3p5.
Moreover, in C99 main() function is somewhat special because lack of
return statement is equivalent with returning zero (5.1.2.2.3p1). Is
it also the case in C89/C90?
No, the value returned in this case is undefined.
BTW. Is there any publicly available (draft of) C89/C90 standard?
I'm sure there is, I don't know where one would find it though.

Robert Gamble

Feb 13 '07 #5
On Feb 13, 1:57 pm, Michal Nazarewicz <min...@tlen.plwrote:
>What does returning 0 from main() mean according to C89/C90 standard?
I've found that in C99 it means successful termination (7.20.4.3p5)
however as I'm editing book on C at Polish Wikibooks I'd like to know
what C89/C90 says about it - quotation from C89 or C90 would be nice.
"matevzb" <ma*****@gmail.comwrites:
First, the main() quote:
"A return from the initial call to the main function is equivalent to
calling the exit function with the value returned by the main function
as its argument. If the main function executes a return that specifies
no value, the termination status returned to the host environment is
undefined."
Return statement:
"Reaching the } that terminates a function is equivalent to executing
a return statement without an expression."
exit() function:
"Finally, control is returned to the host environment. If the value of
status is zero or EXIT_SUCCESS , an implementation-defined form of the
status successful termination is returned. If the value of status is
EXIT_FAILURE , an implementation-defined form of the status
unsuccessful termination is returned. Otherwise the status returned is
implementation-defined."
Thanks, that answers all my questions.

--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86*tlen.pl>---<jid:mina86*chrome.pl>--ooO--(_)--Ooo--
Feb 13 '07 #6
Christopher Benson-Manica <a...@otaku.freeshell.orgwrote:
Michal Nazarewicz <min...@tlen.plwrote:
What does returning 0 from main() mean according to C89/C90
standard?
C89 draft:

"Program termination"

A return from the initial call to the main function is
equivalent to calling the exit function with the value returned
by the main function as its argument. If the main function
executes a return that specifies no value, the termination
status returned to the host environment is undefined.
From n869 [1]:

5.1.2.2.3: "If the return type of the main function is a type
compatible with int, a return from the initial call to the main
function is equivalent to calling the exit function with the
value returned by the main function as its argument;"

7.20.4.3 (The exit function), subparagraph 5: "If the value of
status is zero or EXIT_SUCCESS, an implementation-defined form
of the status successful termination is returned."
Moreover, in C99 main() function is somewhat special because
lack of return statement is equivalent with returning zero
(5.1.2.2.3p1).
True.
Is it also the case in C89/C90?

No; in C89, omission of the return statement causes an unspecified
termination status to be returned [to] the host environment
It does so for the _initial_ call to main. Recursive calls to main
are allowed, and it's possible to perform such calls legitimately
without main ever returning a value, so long as the calling function
doesn't attempt to use the return value.
(I will
leave quoting the relevant portion of the standard to someone with
more time to look it up).
Strictly speaking it says an _undefined_ status will be returned to
the host. Sloppy wording perhaps, but it's probably meant to convey
that the C standard doesn't limit the termination status to something
as simple as an integer value or C like object. For instance, an
unsuccessful status might be to ask the host to ring the lab klaxons!
BTW. Is there any publicly available (draft of) C89/C90 standard?

[1] I apparently have been laboring under the delusion that n869
was a draft of the C89 Standard; a look at the foreward of that
document reveals that it is not so. I also thought the FAQ
addressed this question, but I don't see that either. I've started
my morning 0/2 and mostly failed to be helpful; sorry about that.
N869 is the last public draft prior to the issuance of C99. N1124 is
a more recent draft that includes the TCs.

--
Peter

Feb 13 '07 #7
Peter Nilsson <ai***@acay.com.auwrote:
N869 is the last public draft prior to the issuance of C99. N1124 is
a more recent draft that includes the TCs.
However, N869 describes a language that has much more in common with
C99 than C89, correct? That's the fact that I've previously missed.

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Feb 14 '07 #8
Christopher Benson-Manica <a...@otaku.freeshell.orgwrote:
Peter Nilsson <a...@acay.com.auwrote:
N869 is the last public draft prior to the issuance of C99.
N1124 is a more recent draft that includes the TCs.

However, N869 describes a language that has much more in common
with C99 than C89, correct? That's the fact that I've previously
missed.
It's a draft of C99 yes, but in terms of being a reference for
C89 it's quite useful. N1124 is better still. C99 merely clarified
and extended C89 for the most part. The changes are summarised
in the Forward.

There are differences of course, but C99 reflects the modern
spirit of C better than the crusty C89 standard.

--
Peter

Feb 14 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Bernard | last post by:
Hello, I would like your advices on the following two functions which multiply two arrays. About Multiply_array, I think that this function is ISO C90, but for Product_array I have some...
10
by: Pete | last post by:
Can someone please help, I'm trying to pass an array to a function, do some operation on that array, then return it for further use. The errors I am getting for the following code are, differences...
1
by: Guha | last post by:
I have a problem with returning a 2D array using a function which is called in main(). The piece of the code is given below. This is a test code only. #include"stdio.h" #include"alloc.h" ...
26
by: cdg | last post by:
Could anyone correct any mistakes in this example program. I am just trying to return an array back to "main" to be printed out. And I am not sure how a "pointer to an array" is returned to the...
17
by: I.M. !Knuth | last post by:
Hi. I'm more-or-less a C newbie. I thought I had pointers under control until I started goofing around with this: ...
14
by: dspfun | last post by:
Hi! I am trying to understand weather to use c89/c90 or c99 and have come up with some questions that I would be interested in hearing your thoughts about: What is the advantage of writing a...
80
by: Ioannis Vranos | last post by:
Hi, in C90 is "int main()" valid, the same as "int main(void)" and "int main(int argc, char *argv)"? AFAIK in C99 only "int main(void)" and "int main(int argc, char *argv) - and the **argv...
3
by: Ioannis Vranos | last post by:
Well we all know K&R2 uses main() and not int main(). Also in K&R2, in chapter 4.1, there is a definition of a function: dummy() {} and it is stated that if the returned type is omitted, int...
11
Parul Bagadia
by: Parul Bagadia | last post by:
I m returning a value of pointer of a structure from one function to main; but whenever it comes in main it becomes NULL... i used another pointer in main and equated its value to returning pointer...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.