K
Keith Thompson
dandelion said:It makes the main() return value portable. On Un*x 0 is used to indicate
successful program termination and any non-zero value is (commonly)
interpreted as success (disclaimer: there are a few programs that do not
obey this rule, IIRC).
On other platforms it may be different and a successfull program termination
may be required to return 1, 0xDEADBEEF or anything else. Using
EXIT_SUCCESS, this problem is taken care of (portably) by the header files.
The EXIT_SUCCESS and EXIT_FAILURE macros were introduced in C89 to
allow a portable way for a program to indicate success or failure. In
my opinion, the way it was done was only half a solution.
In Unix, traditionally 0 denotes success, and any non-zero value (most
commonly 1) denotes failure. Other systems have different
conventions. In particular, on VMS 0 (or any even value) denotes
failure, and 1 (or any odd value) denotes success. In ISO C, 0 is
required to indicate success, and EXIT_SUCCESS and EXIT_FAILURE
indicate success and failure, respectively. There's seldom any reason
for EXIT_SUCCESS to have a value other than 0, but it's allowed to do
so.
A better solution, IMHO, would have been to make any value other than
EXIT_SUCCESS or EXIT_FAILURE non-portable. As it is, the standard
made programs that use exit(1) non-portable, but decreed that exit(0)
would continue to be portable, causing a minor implementation headache
for VMS. The result is uglier than it needed to be.