Topic: EXIT_SUCCESS


Author: maciej@maciejsobczak.com ("Maciej Sobczak")
Date: Mon, 4 Nov 2002 04:45:01 +0000 (UTC)
Raw View
Hello,

3.6.1/5 states that main without return is equivalent to main with return 0;
at the end.
18.3/1 defines EXIT_SUCCESS and EXIT_FAILURE macros for portability.

I understand that return 0; is considered non-portable, since its meaning in
the environment is implementation-defined.

Is this a problem in the Standard? Why 3.6.1/5 does not refer to the

"value equal to the EXIT_SUCCESS macro"

or something similar?

Cheers,

--
Maciej Sobczak
http://www.maciejsobczak.com/



---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: loewis@informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=)
Date: Mon, 4 Nov 2002 08:28:10 +0000 (UTC)
Raw View
maciej@maciejsobczak.com ("Maciej Sobczak") writes:

> Is this a problem in the Standard? Why 3.6.1/5 does not refer to the
>
> "value equal to the EXIT_SUCCESS macro"
>
> or something similar?

Sounds like a defect to me.

Regards,
Martin

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: jackklein@spamcop.net (Jack Klein)
Date: Mon, 4 Nov 2002 08:28:12 +0000 (UTC)
Raw View
On Mon, 4 Nov 2002 04:45:01 +0000 (UTC), maciej@maciejsobczak.com
("Maciej Sobczak") wrote in comp.std.c++:

> Hello,
>
> 3.6.1/5 states that main without return is equivalent to main with return 0;
> at the end.
> 18.3/1 defines EXIT_SUCCESS and EXIT_FAILURE macros for portability.
>
> I understand that return 0; is considered non-portable, since its meaning in
> the environment is implementation-defined.
>
> Is this a problem in the Standard? Why 3.6.1/5 does not refer to the
>
> "value equal to the EXIT_SUCCESS macro"
>
> or something similar?
>
> Cheers,

You are confusing the value 0 in a C++ (or C program) with the value
that a particular operating system accepts as an indication of
successful completion.  This is just the same as using 0 as a null
pointer value.

Just as it is up to the compiler to understand that 0 represents a
null pointer value and translate that into the platform's
representation of a null pointer, which might not have all bits 0, the
implementation is required to translate 0 or EXIT_SUCCESS into
whatever value the host operating system wants to see.

Remember, that return in main() does not immediately transfer control
back to the operating system.  In C, the runtime library is required
to flush all buffered output to files and then close all files, and
call all functions registered with atexit().  In C++ it must do all of
these things and also invoke destructors for all objects with static
storage duration.

Sometime after completing all of that, it will translate the value
returned by main() into whatever the host system requires, if that
value was 0 or EXIT_SUCCESS, or if it was EXIT_FAILURE.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: loewis@informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=)
Date: Mon, 4 Nov 2002 09:44:18 +0000 (UTC)
Raw View
loewis@informatik.hu-berlin.de (Martin v. L=F6wis) writes:

> > Is this a problem in the Standard? Why 3.6.1/5 does not refer to the
> >=20
> > "value equal to the EXIT_SUCCESS macro"
> >=20
> > or something similar?
>=20
> Sounds like a defect to me.

I withdraw this comment; 18.3/8 says that both 0 and EXIT_SUCCESS
should be considered as successful termination.

Regards,
Martin

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: andys@evo6.com.NoSpam (Andy Sawyer)
Date: Mon, 4 Nov 2002 15:51:10 +0000 (UTC)
Raw View
In article <j4vg3d69lx.fsf@informatik.hu-berlin.de>,
 on Mon, 4 Nov 2002 08:28:10 +0000 (UTC),
 loewis@informatik.hu-berlin.de (Martin v. L=F6wis) wrote:

> maciej@maciejsobczak.com ("Maciej Sobczak") writes:
>=20
> > Is this a problem in the Standard? Why 3.6.1/5 does not refer to the
> >=20
> > "value equal to the EXIT_SUCCESS macro"
> >=20
> > or something similar?
>=20
> Sounds like a defect to me.

Based on what? A careful reading of the standard shows that "return
0;" at the end of main has the same effect as "return EXIT_SUCCESS:".

Regards,
 Andy S.
--=20
"Light thinks it travels faster than anything but it is wrong. No matter
 how fast light travels it finds the darkness has always got there first,
 and is waiting for it."                  -- Terry Pratchett, Reaper Man

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: andys@evo6.com.NoSpam (Andy Sawyer)
Date: Mon, 4 Nov 2002 17:44:34 +0000 (UTC)
Raw View
In article <aq4872$38m$1@sunsite.icm.edu.pl>,
 on Mon, 4 Nov 2002 04:45:01 +0000 (UTC),
 maciej@maciejsobczak.com ("Maciej Sobczak") wrote:

> Hello,
>
> 3.6.1/5 states that main without return is equivalent to main with return 0;
> at the end.
> 18.3/1 defines EXIT_SUCCESS and EXIT_FAILURE macros for portability.
>
> I understand that return 0; is considered non-portable, since its meaning in
> the environment is implementation-defined.

 No, the semantics of return 0 are well-defined (or at least, as
well-defined as those of return EXIT_SUCCESS")

> Is this a problem in the Standard?

 I don't consider it to be so.

> Why 3.6.1/5 does not refer to the
>
> "value equal to the EXIT_SUCCESS macro"
>
> or something similar?

Because there's no benefit to doing so. In this context, 0 is
functionaly equivalent to EXIT_SUCCESS.

3.6.1 para 5 says:
,----
| A return statement in main has the effect of leaving the main function
| (destroying any objects with automatic storage duration) and calling
| exit with the return value as the argument. If control reaches the end
| of main without encountering a return statement, the effect is that of
| executing return 0;
`----

So "return 0" ends up calling "exit(0)", whilst "return EXIT_SUCCESS"
ends up calling "exit(EXIT_SUCCESS)". These are equivalent actions.

18.3 para 8 says:

,----
| If status is zero or EXIT_SUCCESS, an implementation-defined form of
| the status *successful termination* is returned.
`----

So clearly exit(0) has identical behaviour to exit(EXIT_SUCCESS).
Ergo, in main, "return 0;" has the same effect as "return EXIT_SUCCESS;".

 That being said, I'm inclined to suggest that in any case where the
return value from main is important, the the return statment should
be explicitly written.

Regards,
 Andy S.
--
"Light thinks it travels faster than anything but it is wrong. No matter
 how fast light travels it finds the darkness has always got there first,
 and is waiting for it."                  -- Terry Pratchett, Reaper Man

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: kuyper@wizard.net ("James Kuyper Jr.")
Date: Mon, 4 Nov 2002 17:48:40 +0000 (UTC)
Raw View

Maciej Sobczak wrote:
> Hello,
>
> 3.6.1/5 states that main without return is equivalent to main with return 0;
> at the end.
> 18.3/1 defines EXIT_SUCCESS and EXIT_FAILURE macros for portability.
>
> I understand that return 0; is considered non-portable, since its meaning in
> the environment is implementation-defined.

18.3p8: "If _status_ is zero or EXIT_SUCCESS, and 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.

The meaning of zero is therefore no less well defined than the meaning
of EXIT_SUCCESS. Also, note that zero is neither required to compare
equal to the value represented by the expansion of EXIT_SUCCESS, nor
prohibited from comparing equal.

> Is this a problem in the Standard? Why 3.6.1/5 does not refer to the
>
> "value equal to the EXIT_SUCCESS macro"

Because that's not what was intended. On an implementation where the
expansion of EXIT_SUCCESS has a non-zero value, implicit return from
main() returns 0, not EXIT_SUCCESS.

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]