Subject: Re: a few minor cleanups to src/share/misc/style
To: cgd@sibyte.com (Chris G. Demetriou), Greywolf <greywolf@starwolf.com>
From: Erik Bertelsen <ebe-list@get2net.dk>
List: tech-userlevel
Date: 03/22/2001 08:59:10
At 19:16 -0800 21/03/01, Chris G. Demetriou wrote:
>Greywolf <greywolf@starwolf.com> writes:
>> Can I ask what the point is of (strongly) suggesting such things as
>> EXIT_SUCCESS and EXIT_FAILURE as opposed to 0 and 1? That just
>> seems such a PITA.
>
>(1) They're more portable. I.e., really, not all systems which support
>'standard C' use success == 0 and failure == non-zero. Sure, those
>systems aren't really unix, but since KNF already says 0 / 1, it seems
>fairly obvious and non-bad to use the standards-defined exit codes.
Actually my reading of the c89 standard (section 7.10.4.3 about the
exit function) is that an application is specifically allowed to use
either EXIT_SUCCESS or 0 in the call to exit to indicate success. The
actual exit status returned to the calling program need not be the
parameter value given to exit(), e.g. on VMS (IIRC) a successful exit
is indicated by an exit status of 1.
this section of the standard also contains: "If the value of status
[the parameter to exit()] is EXIT_FAILURE, an implementation-defined
form of the status unsucessful termination is returned. Otherwise the
status returned is implementation-defined".
In particular the last phrase indicates to me that the use of
exit(EXIT_SUCCESS) and exit(0) has exactly the same level of
conformance to c89 and of portabiblity. You may argue that the use of
exit(EXIT_FAILURE) has a slight win over EXIT_FAILURE as a portable
way of indicating a generic program failure.
As a matter of every-day experience, exit(0)/exit(1) will probably
work in most, but not necessarily all C environments.
For NetBSD-specific userland programs the I see no real difference
between using 0/1 instead of EXIT_SUCCESS/EXIT_FAILURE, but
applications that try to be generally portable (which is/could be a
significant part of the NetBSD userland), there is some indication
from the abouve mentioned text from c89 that EXIT_SUCCESS and in
particular EXIT_FAILURE are preferred to 0 and 1 as parameters to
exit().
- Erik