473,883 Members | 1,585 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
25 15647
Tim Woodall wrote:

On Tue, 25 Nov 2003 14:30:38 GMT,
Wojtek Lerch <Wo******@yahoo .ca> wrote:
"Mike Wahler" <mk******@mkwah ler.net> wrote in message
news:L9******** ***********@new sread1.news.pas .earthlink.net. ..
"Arthur J. O'Dwyer" <aj*@nospam.and rew.cmu.edu> wrote in message
news:Pi******** *************** ************@un ix46.andrew.cmu .edu...

> void *q = EXIT_SUCCESS;

The behavior of this is implementation defined.


If the value is nonzero, this is a constraint violation.


Why? It must be an integer (or convert to an integer) in order for
it to be a valid return from main. And integers can be converted
to pointers in an implementation defined way.


Section 6.5.4p3: "Conversion s that involve pointers, other than where
permitted by the constraints of 6.5.16.1, shall be specified by means of
an explicit cast." If EXIT_SUCCESS has a value of 0, then it counts as a
null pointer constant, which is permitted by 6.5.16.1. Otherwise, the
absence of an explicit cast is indeed a constraint violation.

Even if you change the code to use an explicit cast, one remaining
potential problem applies. Per section 6.3.2.3p6: "... Except as
previously specified, the result is implementation-defined, might not be
correctly aligned, might not point to an entity of the referenced type,
and might be a trap representation. "

Per footnote 41, a trap representation can be stored in 'q', but any
attempt to actually use the value of 'q' has undefined behavior.
Footnotes aren't normative, but this one correctly summarizes the
consequences of normative text in the standard.
Nov 13 '05 #21
In <41************ **************@ posting.google. com> ne*****@tokyo.c om (Mantorok Redgormor) writes:
Da*****@cern.c h (Dan Pop) wrote in message news:<bp******* ***@sunnews.cer n.ch>...
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?

well I was using EXIT_FAILURE in a few functions to serve as a
failure returned.


That's a bad idea. EXIT_FAILURE has well defined semantics *only* as
argument to an exit function call.
which is why I was ensuring if EXIT_SUCCESS
is guaranteed to be zero, which it isn't. So that route is messy.
All three can be defined as zero, if the execution environment does not
support the concept of program exit status.
I guess I could instead use

#define FAILURE 1
#define SUCCESS 0


Or, even better:

#define FAILURE 0
#define SUCCESS 1

but there is no consensus on that. Unix programmers may prefer

#define FAILURE -1
#define SUCCESS 0

for consistency with the Unix system calls.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #22
"Ben Pfaff" <bl*@cs.stanfor d.edu> wrote in message
news:87******** ****@pfaff.stan ford.edu...
"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"?

To imply that EXIT_SUCCESS (integer constant expression
after expansion) is "synonym" for literal 0. I would agree,
if it said (7 or 55 or 123). But I'm not native (English
speaker), so I won't argue.
5.1.2.2.3p1 ... reaching the } that terminates the main
function returns a value of 0. ...


Nothing to do with the former statement.

So this case (fall through) is a successful termination or
an unsuccessful one?
(Though not explicitly stated, I read it as successful,
together with quote above that gives me that EXIT_SUCCESS
evaluates to 0. But I'm known to err on ocassion.)
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


Yeah. Especially true about C standard(s) :-)
Nov 13 '05 #23
"nobody" <no****@nowhere .non> writes:
"Ben Pfaff" <bl*@cs.stanfor d.edu> wrote in message
news:87******** ****@pfaff.stan ford.edu...
"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"?

To imply that EXIT_SUCCESS (integer constant expression
after expansion) is "synonym" for literal 0. I would agree,
if it said (7 or 55 or 123). But I'm not native (English
speaker), so I won't argue.


My interpretation: 7.20.4.3p5 says that there are two things you can
portably pass to exit(), which cause "successful termination" to be
returned to the surrounding environment. One is 0, and the other is
EXIT_SUCCESS. 7.20p1 says that EXIT_SUCCESS expands to an integer
constant expression, but the value of that expression is undefined.

If memory serves, at least some versions of VMS C defined EXIT_SUCCESS
to be 1.

You may be wondering 'why define EXIT_SUCCESS at all if 0 has the same
effect?' It is presumably for symmetry with EXIT_FAILURE. Also, the
fact that it might not be 0 is a caution to writers of portable code
not to use numeric arguments to exit() other than 0. The very common
convention of using exit(1) in Unix command line utilities to indicate
failure, for instance, is not portable; it would fail under those VMS C
versions discussed above.

zw
Nov 13 '05 #24
In <87************ @egil.codesourc ery.com> Zack Weinberg <za**@codesourc ery.com> writes:
You may be wondering 'why define EXIT_SUCCESS at all if 0 has the same
effect?' It is presumably for symmetry with EXIT_FAILURE.


EXIT_SUCCESS is the C89 way of doing it, while 0 is obviously supported
because it was the (most common) existing practice. Things would
have been much clear if C89 deprecated the usage of 0 for this purpose.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #25
James Kuyper wrote:
Implementation-defined is a subset of "unspecifie d". The alternatives
for "unspecifie d" are not required to be "few", the only requirement is
that there be at least two of them. In this case, EXIT_SUCCESS can be
defined as expanding into any string of characters that constitutes an
integer constant expression that can be safely converted to an int; the
expression's value need not itself be within the valid range of an int.
There is a discrete infinity of such expressions, which becomes finite,
but still huge, if you put an upper limit on the length of that
character string.


I think you should lay off the -pedantic flag for a while :-þ

Nov 13 '05 #26

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

Similar topics

5
2534
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 ); xmlhttp1.send( data1 );
19
2546
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
6463
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 values in my shell scripts. Say I move to another platform, but with the same shell, can I still rely...
10
4601
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 Product Is Null. SELECT COUNT(*) AS CountofNullProdcut
11
3075
by: active | last post by:
The code below does much as expected. For example biSize=40 but biClrUsed is always zero!
0
9933
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9781
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10407
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9564
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7960
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5982
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4606
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
2
4210
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3230
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.