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
mi...@nosc.mil
ANSI C also allows exit(0) and return 0; to indicate success. All of the
standard C functions are part of C++. Use either #include <stdlib.h> or
#include <cstdlib> to get exit, EXIT_SUCCESS, and EXIT_FAILURE.
--
Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Contributing Editor, C/C++ Users Journal (http://www.cuj.com)
Specifically, where does the ANSI C standard say that 0 universally means
success?
Oddly enough, in the specification for the exit function.
In the 1990 edition:
Subclauses 5.1.2.2.3 "Program termination" and 7.10.4.3 "The exit
function".
I don't have the new Standard yet.
Victor
--
Please remove capital A's from my address when replying by mail
Pete Becker <peteb...@acm.org> wrote in message
news:39873006...@acm.org...
> Ray Mitchell wrote:
> >
> > Pete Becker <peteb...@acm.org> wrote in message
> > news:39871616...@acm.org...
> > >
> > > ANSI C also allows exit(0) and return 0; to indicate success.
> >
> > Specifically, where does the ANSI C standard say that 0 universally
means
> > success?
> >
>
"Ray Mitchell" <mi...@nosc.mil> wrote in message
news:8m6rum$c2m$1...@newpoisson.nosc.mil...
> 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
> mi...@nosc.mil
>
ISO/IEC 14882 18.3
header <cstdlib> defines EXIT_SUCCESS and EXIT_FAILURE
--
Rob Sykes
Remove NOSPAM to e-mail
This is one of those "compromises" that occurs when committees do language
specifications. In the days before Win 3.0, most C programming was done on
Unix and [later] VMS.
On Unix 0 mean sucess as an exit status code. On VMS, 1 was the normal exit
status code and 0 was a perfectly legal status indicating a warning. [VMS had
a much more powerful system for defining messages than Unix or Windows ever
have.] Naturally, the DEC folks wanted to have some standard method of
indicating success that would work for VMS so we get EXIT_SUCCSS and
EXIT_FAILURE.
Now that VMS is dead, these macros serve very little purpose. Using 0 for
successful completion or a non-zero value for an error is nearly universal and
portable. That is why you rarely see these macros in books.
John - N8086N
Big brother is watching. Disable cookies in your web browser.
-------------------------------------------
Wise man says "Never use a bank with the initials F. U."
-------------------------------------------
Are you interested in a professional society or
guild for programmers? Want to fight section 1706?
See www.programmersguild.org
Newsgroup: us.issues.occupations.computer-programmers
EMail Address:
_m-i-a-n-o_@_c_o_l_o_s_s_e_u_m_b_u_i_l_d_e_r_s._c_o_m_
>Now that VMS is dead, these macros serve very little purpose. Using 0 for
>successful completion or a non-zero value for an error is nearly universal and
>portable. That is why you rarely see these macros in books.
Actually, using 0 for successful termination is completely
portable to compilers that correctly implement the standard. 0
returns a successful termination status according to the
standard.
Standard C (and C++ if there are any) implementations under VMS
must do whatever it takes to return success when 0 is returned
from main.
The problem is failure. The only return from main that the
standard specifies as returning unsuccessful termination status
is EXIT_FAILURE.