473,574 Members | 2,230 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

EXIT_SUCCESS guaranteed to always be zero?

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.

beyond this paragraph from the standard, I can't determine if this
macro
will always be zero. It would surely be convenient if it is but it
never
states this directly. the "zero or" part, leads me to believe that the
macro
can be something other than zero, but I'm not too sure.

--
nethlek
Nov 13 '05 #1
25 15602
In comp.lang.c Mantorok Redgormor <ne*****@tokyo. com> wrote:
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. beyond this paragraph from the standard, I can't determine if this
macro
will always be zero. It would surely be convenient if it is but it
never
states this directly. the "zero or" part, leads me to believe that the
macro
can be something other than zero, but I'm not too sure.


You are correct. The wording of the standard does not dictate the
value of EXIT_SUCCESS, nor EXIT_FAILURE.

All you have to know is that 0 and EXIT_SUCCESS are functional
synonyms that denote successful program completion. In fact,
the value returned to the environment does necessarily have
to correspond to the value returned within the program. It
just has to indicate that the program completed successfully,
in an implementation defined manner.

Alex
Nov 13 '05 #2
ne*****@tokyo.c om (Mantorok Redgormor) writes:
beyond this paragraph from the standard, I can't determine if
this macro will always be zero. It would surely be convenient
if it is but it never states this directly. the "zero or" part,
leads me to believe that the macro can be something other than
zero, but I'm not too sure.


The standard doesn't state or imply that EXIT_SUCCESS is always
0, so you can't portably depend on it.
--
"Your correction is 100% correct and 0% helpful. Well done!"
--Richard Heathfield
Nov 13 '05 #3
Alex <al*******@hotm ail.com> writes:
In comp.lang.c Mantorok Redgormor <ne*****@tokyo. com> wrote:
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.

beyond this paragraph from the standard, I can't determine if this
macro will always be zero. It would surely be convenient if it is but
it never states this directly. the "zero or" part, leads me to believe
that the macro can be something other than zero, but I'm not too sure.


You are correct. The wording of the standard does not dictate the
value of EXIT_SUCCESS, nor EXIT_FAILURE.

All you have to know is that 0 and EXIT_SUCCESS are functional
synonyms that denote successful program completion. In fact,
the value returned to the environment does necessarily have
to correspond to the value returned within the program. It
just has to indicate that the program completed successfully,
in an implementation defined manner.


0 and EXIT_SUCCESS aren't necessarily synonymous (though the wording
in the standard could be read to indicate that they are). They could
indicate different kinds of success. Of course, a portable program
can't make use of the distinction, if any.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
(Note new e-mail address)
Nov 13 '05 #4
"Ben Pfaff" <bl*@cs.stanfor d.edu> wrote in message
news:87******** ****@pfaff.stan ford.edu...
ne*****@tokyo.c om (Mantorok Redgormor) writes:
beyond this paragraph from the standard, I can't determine if
this macro will always be zero. It would surely be convenient
if it is but it never states this directly. the "zero or" part,
leads me to believe that the macro can be something other than
zero, but I'm not too sure.


The standard doesn't state or imply that EXIT_SUCCESS is always
0, so you can't portably depend on it.


7.20.4.3p5 ... If the value of status is zero or EXIT_SUCCESS,
-----------------------------------------^^^^^^^^^^^^^^^ ^^^^^
an implementation-defined form of the status successful
termination is returned. ...

5.1.2.2.3p1 ... reaching the } that terminates the main
function returns a value of 0. ...

If those two together are not "statement" , aren't they
at least implication?

Related question of my own (I asked about this topic
some months ago and don't want to seem obtuse - just want
to understand issues). Standard talks about returning to
the host environment. Only way I know of to (portably?)
execute another (C) program from C program is system()
call. However, 7.20.4.5p3 states (about system()) "If the
argument is not a null pointer, and the system function
does return, it returns an implementation-defined value."
Doesn't it all together imply that success/failure of
a C program can be portably "returned", but not "retrieved"
(in a portable manner)? If yes, then *portable* "return to
host environment" doesn't make much sense, does it? (I'm
not interested in portable return to e.g. Java program).
(If no,) I will really appreciate clarification (as
always, even if I don't state so).
Thanks. (It's not sig, I'm not impersonating Tom:-)
Nov 13 '05 #5
"nobody" <no****@nowhere .non> writes:
"Ben Pfaff" <bl*@cs.stanfor d.edu> wrote in message
news:87******** ****@pfaff.stan ford.edu...
ne*****@tokyo.c om (Mantorok Redgormor) writes:
beyond this paragraph from the standard, I can't determine if
this macro will always be zero. It would surely be convenient
if it is but it never states this directly. the "zero or" part,
leads me to believe that the macro can be something other than
zero, but I'm not too sure.
The standard doesn't state or imply that EXIT_SUCCESS is always
0, so you can't portably depend on it.


7.20.4.3p5 ... If the value of status is zero or EXIT_SUCCESS,
-----------------------------------------^^^^^^^^^^^^^^^ ^^^^^
an implementation-defined form of the status successful
termination is returned. ...


If EXIT_SUCCESS is always zero, then why the "or"?
5.1.2.2.3p1 ... reaching the } that terminates the main
function returns a value of 0. ...
Nothing to do with the former statement.
If those two together are not "statement" , aren't they
at least implication?


No.
--
"I hope, some day, to learn to read.
It seems to be even harder than writing."
--Richard Heathfield
Nov 13 '05 #6

On Tue, 24 Nov 2003, Ben Pfaff wrote:

"nobody" <no****@nowhere .non> writes:
"Ben Pfaff" <bl*@cs.stanfor d.edu> wrote...

The standard doesn't state or imply that EXIT_SUCCESS is always
0, so you can't portably depend on it.


7.20.4.3p5 ... If the value of status is zero or EXIT_SUCCESS,
-----------------------------------------^^^^^^^^^^^^^^^ ^^^^^
an implementation-defined form of the status successful
termination is returned. ... ^^^


If EXIT_SUCCESS is always zero, then why the "or"?


[Because it is possible that (EXIT_SUCCESS != 0).]
If those two together are not "statement" , aren't they
at least implication?


No.


I see the problem here. IMHO, EXIT_SUCCESS and zero *are*
synonymous *in the context of a call to exit()*. Note that
I've added a line under the word "the" in 7.20.4.3p5, which
to me indicates that there is only one possible status
"successful termination" in C, and it's triggered by both
0 and EXIT_SUCCESS, equivalently.
However, 0 and EXIT_SUCCESS are obviously *not* equivalent
in all contexts. To take the canonical extreme example,

void *p = 0;
void *q = EXIT_SUCCESS;

are certainly not equivalent! But I do believe the Standard
guarantees that

exit(0);
exit(EXIT_SUCCE SS);

are exactly equivalent under all implementations , no matter
the actual integer value of EXIT_SUCCESS.

-Arthur
Nov 13 '05 #7
nobody wrote:
5.1.2.2.3p1 ... reaching the } that terminates the main
function returns a value of 0. ...
which is one form of returning a successful termination
status to the invoking environment. EXIT_STATUS could
have a value different from 0, and in fact it did on
VAX/VMS at one point in time (the system convention was
that even-values status returns indicated failure and
odd-values ones success, but since there was no failure
code 0 the C run-time system was able to convert any 0
return into an odd value before handing it back to the
environment).
Doesn't it all together imply that success/failure of
a C program can be portably "returned", but not "retrieved"
(in a portable manner)? If yes, then *portable* "return to
host environment" doesn't make much sense, does it? (I'm
not interested in portable return to e.g. Java program).


It makes plenty of sense, for example to use programs
properly in Unix shell scripts they must correctly
indicate whethr they succeeded or failed. Similarly
for other host command environments. There is more to
computing than just C.

Nov 13 '05 #8

"Arthur J. O'Dwyer" <aj*@nospam.and rew.cmu.edu> wrote in message
news:Pi******** *************** ************@un ix46.andrew.cmu .edu...

On Tue, 24 Nov 2003, Ben Pfaff wrote:

"nobody" <no****@nowhere .non> writes:
"Ben Pfaff" <bl*@cs.stanfor d.edu> wrote...
>
> The standard doesn't state or imply that EXIT_SUCCESS is always
> 0, so you can't portably depend on it.

7.20.4.3p5 ... If the value of status is zero or EXIT_SUCCESS,
-----------------------------------------^^^^^^^^^^^^^^^ ^^^^^
an implementation-defined form of the status successful
termination is returned. ... ^^^
If EXIT_SUCCESS is always zero, then why the "or"?


[Because it is possible that (EXIT_SUCCESS != 0).]
If those two together are not "statement" , aren't they
at least implication?


No.


I see the problem here. IMHO, EXIT_SUCCESS and zero *are*
synonymous *in the context of a call to exit()*. Note that
I've added a line under the word "the" in 7.20.4.3p5, which
to me indicates that there is only one possible status
"successful termination" in C, and it's triggered by both
0 and EXIT_SUCCESS, equivalently.
However, 0 and EXIT_SUCCESS are obviously *not* equivalent
in all contexts. To take the canonical extreme example,

void *p = 0;


Here, the 0 does not signify an integral zero, but a null pointer.
void *q = EXIT_SUCCESS;
The behavior of this is implementation defined.

are certainly not equivalent! But I do believe the Standard
guarantees that

exit(0);
exit(EXIT_SUCCE SS);

are exactly equivalent under all implementations , no matter
the actual integer value of EXIT_SUCCESS.


Right, because in both these cases the argument is an integer
value, with the pointer examples above, it is not.

-Mike
Nov 13 '05 #9
In <41************ **************@ posting.google. com> ne*****@tokyo.c om (Mantorok Redgormor) writes:
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.

beyond this paragraph from the standard, I can't determine if this
macro
will always be zero. It would surely be convenient if it is but it
never
states this directly. the "zero or" part, leads me to believe that the
macro
can be something other than zero, but I'm not too sure.


Please explain why do you think it matters whether EXIT_SUCCESS can be
something else than zero or not. Are you planning to use EXIT_SUCCESS
instead of zero in other contexts than exit() calls?

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #10

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

Similar topics

5
2525
by: Ranju. V | last post by:
Hi, I use a lot asynchronous XMLHTTP from JavaScript. Are the callbacks that we register with XMLHTTP guaranteed to execute single-threaded? For instance, consider the following code snippet. var xmlhttp1 = new ActiveXObject( "Msxml2.XMLHTTP.4.0" ); xmlhttp1.onreadystatechange = callback; xmlhttp1.open( "POST", "foo.aspx", true );...
19
2524
by: Mark A. Odell | last post by:
Is NULL guaranteed to evaluate 'not true', e.g. is it completely safe and portable to write: char *pFoo = malloc(1024); if (pFoo) { /* use pFoo */ free(pFoo); }
13
6441
by: William Payne | last post by:
Hello, I would like to know if EXIT_FAILURE/SUCCESS has the same value on all platforms? I am writing a few scripts (I know shell scripts are off-topic here) to test my C programs and they depend on looking at the return values to know what to do. Since EXIT_FAILURE/SUCCESS are not constants visible to the shell, I have to hard code their...
10
4567
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaac11/html/acfctNZ_HV05186465.asp "If the value of the variant argument is Null, the Nz function returns the number zero or a zero-length string (always returns a zero-length string when used in a query expression)" **** How many records are there in FirstTable in which...
11
3052
by: active | last post by:
The code below does much as expected. For example biSize=40 but biClrUsed is always zero!
0
7803
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7720
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8044
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7810
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8096
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6451
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5299
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3749
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2240
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.