Topic: EXIT_SUCCESS and EXIT_FAILURE


Author: "Ray Mitchell" <mitch@nosc.mil>
Date: 2000/08/03
Raw View
Hello,

I've been into C for a long time but am just getting into C++.  Since not
all operating systems running C programs interpreted an exit code of 0 as
success, the ANSI C standard required that two macros, EXIT_SUCCESS and
EXIT_FAILURE, be defined so that the appropriate success and error codes
could be generated regardless of the operating system.  However, I find no
mention of them in the C++ standard, but rather, an exit value of 0 is often
used.  I've looked but can't find anyplace in the standard that states that
an exit code of 0 SHALL be interpreted by the operating system as a success
code.  On the other hand, it seems like using EXIT_SUCCESS and EXIT_FAILURE
in C++ would be considered an anachronism since I've never seen it in any of
the literature.  Please fill me in on this, preferably quoting chapter and
verse.

Ray Mitchell
mitch@nosc.mil


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: James Kuyper <kuyper@wizard.net>
Date: 2000/08/04
Raw View
Ray Mitchell wrote:
>
> Hello,
>
> I've been into C for a long time but am just getting into C++.  Since not
> all operating systems running C programs interpreted an exit code of 0 as
> success, the ANSI C standard required that two macros, EXIT_SUCCESS and
> EXIT_FAILURE, be defined so that the appropriate success and error codes
> could be generated regardless of the operating system.  However, I find no
> mention of them in the C++ standard, but rather, an exit value of 0 is often
> used.  I've looked but can't find anyplace in the standard that states that
> an exit code of 0 SHALL be interpreted by the operating system as a success
> code.  On the other hand, it seems like using EXIT_SUCCESS and EXIT_FAILURE
> in C++ would be considered an anachronism since I've never seen it in any of
> the literature.  Please fill me in on this, preferably quoting chapter and
> verse.

Section 3.6.1p5 says that "A return statement in main has the effect of
.... calling exit with the return value as the argument".

Section 18.3p8 says about exit(status) that "Finally, control is
returned to the host environment. If _status_ is zero or EXIT_SUCCESS,
an implementation-defined form of the status _successful termination_ is
returned. If _status_ is EXIT_FAILURE, an implementation-defined form of
the status _unsuccessful termination_ is returned. Otherwise, the status
returned is implementation-defined."

You are correct; the standard doesn't say that 0 shall be interpreted as
a success code; only that it be converted into a _successful
termination_ status, whatever that means in that particular operating
system. Note that the standard is very careful not to define what the
_successful termination_ and _unsuccessful termination_ statuses are. It
doesn't specify what values they have. It doesn't even specify that
they're represented by numbers - which is good, because many operating
systems have no such concept as an exit status number. The standard is
even vague enough to allow for an implementation where there's no
detectable difference between "exit(EXIT_SUCCESS)" and
"exit(EXIT_FAILURE)".

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]