Peter said:
Perhaps none now, but in the past it was certainly a
possibility on some of the VAX systems.
Under VMS (which isn't quite dead, and runs on both VAX and Alpha
hardware, and possibly others), the OS convention is that returning an
even number from a program indicates success, and returning an odd
number indicates failure. This obviously conflicts with the convention
of using exit(0) to indicate success. However, the C runtime works
around this by translating "exit(0)" or "return 0" so that it returns
the value 1 (indicating success) to the environment. It *doesn't* do a
similar translation for "exit(1)".
As I recall (from using VMS about 10 years ago), EXIT_SUCCESS is defined
as 0, and EXIT_FAILURE is defined as some non-zero even number (perhaps
2). So exit(0) and exit(EXIT_SUCCESS) are exactly equivalent, even
under VMS.
This may have been different in the distant past.
Perhaps more critical to that scenario is that
EXIT_FAILURE need not have a non-zero value or be
different to EXIT_SUCCESS.
True, but if the OS provides a way for a program to indicate success or
failure, it will almost certainly define EXIT_FAILURE as a non-zero
value different from the value of EXIT_SUCCESS. If the OS has no such
mechanism, then the C implementation might as well define both
EXIT_SUCCESS and EXIT_FAILURE as 0 -- but I don't know of any such systems.
Given that both exit(0) and exit(EXIT_SUCCESS) must indicate success (if
that's possible), I can't think of any reason for EXIT_SUCCESS to have a
value other than 0.
In my opinion, requiring exit(0) (or return 0) to denote success was an
over-specification. Traditionally, in Unix, exit(0) indicates success,
and exit(1) indicates a non-specific failure. The C standard broke the
latter, but not the former.
I suppose the rationale was that if there were no guarantees about
exit(0), then any program that wants to terminate normally must have a
"#include <stdlib.h>" so it can use EXIT_SUCCESS.
If C89 hadn't required 0 to denote success, then C99's rule about
falling off the end of main would actually have made sense; it could
have said that reaching the closing "}" is equivalent to returning
EXIT_SUCCESS. But that's not what happened.