Keith Thompson wrote On 01/19/06 16:14,:
And since 0 is required to indicate success, there's probably no good
reason for an implementation to define EXIT_SUCCESS as anything other
than 0 -- but it could, and you shouldn't assume that EXIT_SUCCESS==0.
(There's little reason to make such an assumption anyway.)
The very O/S you proceed to cite offers a good reason
for EXIT_SUCCESS != 0 ...
IMHO, the standard would have been clearer and more consistent if it
had *not* required 0 to indicate success, just defining EXIT_SUCCESS
and EXIT_FAILURE with implementation-specific values. The requirement
causes some problems for VMS^H^H^H OpenVMS, where odd values denote
success and even values denote errors; the C runtime system has to
make special allowances for "return 0;".
In the Very Old Days, a C program's exit status was
passed back verbatim as a VMS condition code, so exit(0)
meant "failure" ("warning," actually -- there were five
severity levels) and exit(1) meant "success." At some
point DEC decided to bow to prevailing custom, and put
in a hack that mapped 0->1 and 1->0 but left other values
untouched. That way, exit(0) and exit(1) had the meanings
on VMS that were not too different from what people were
accustomed to on Unix, while VMS-aware programs could still
exit with more informative VMS codes.
Then the Standard came along, and we had EXIT_SUCCESS
and EXIT_FAILURE. If I recall correctly (it's been a few
years), DEC didn't define EXIT_SUCCESS as 0 and let the
library change it to 1, but defined it as a large odd
number, turning "generic success" into "success of C program."
Similarly, EXIT_FAILURE wasn't defined as 1 to be mapped to
0, but as a large even value meaning "failure of C program."
Sounds like a silly distinction when viewed in isolation,
but remember: VMS condition codes were structured, with
various fields conveying different pieces of information.
By picking apart the fields you could determine not only
success/failure, but a severity level (five were defined),
a specific condition (a program could succeed in many ways,
or fail in many ways), and the system component where the
condition arose. A bare zero or one omitted most of this
information, whereas EXIT_xxxx supplied it.