Article View: comp.std.c
Article #3840Re: EXIT_FAILURE problem
From: Stephen Baynes
Date: Thu, 24 Aug 1995 07:35
Date: Thu, 24 Aug 1995 07:35
95 lines
4072 bytes
4072 bytes
Derick J.R. Qua-Gonzalez (dqua@earthlink.net) wrote:
: In comp.lang.c and comp.std.c, caip.rutgers.edu!halasz writes:
: >In article <411j5n$3va@goanna.cs.rmit.edu.au>,
: >ok@goanna.cs.rmit.edu.au (Richard A. O'Keefe) writes:
: >: .... An operating system can use any status convention it likes.
: >: VMS status codes are really packed records, with "severity",
: >: "source", and other fields. If I recall correctly, Plan 9 uses
: >: strings. The B6700 MCP allowed arbitrary 48-bit patterns, some of
: >: which were integers and most of which weren't.
-snip-
: The problem with this approach is exactly the variance in the exit
: "codes" accepted by different systems. Then we'd be forced to
: compensate with something that looks like:
: #ifdef OS_VMS
: exit(1);
: #endif
: #ifdef OS_B6700_MCP
: exit(B6700_MCP_EXIT_SUCCESS);
: #endif
: #ifdef OS_PLAN_9
: exit("Whee! It worked!");
: #endif
: #ifdef OS_UNIX
: exit(0);
: #endif
-snip-
And also:
#ifdef OS_VMS
int main( char const *argline )
#endif
#ifdef OS_B6700_MCP
int main( ??? )
#endif
#ifdef OS_PLAN_9
char const *main( ??? )
#endif
#ifdef OS_UNIX
int main( int argc, char **argv )
#endif
To what extent should the programing language change to suite the operating
system and to what extent should the operating system change to suite the
programing language? Exit codes sounds like a case where one could expect
ones OS to make sensible use of a simple integer value system rather than
try and fit the program to the system. In a sense we have this, but only
two values portable - 0/EXIT_SUCCESS and EXIT_FAILURE.
Perhaps one should have a guarentee of 128 distinguishable exit status.
[I use exit-status to mean the value returned from main and OS-status as the
OS's program exit status.]
I would propose that:
0 and EXIT_SUCCESS (which could also be 0) will produce a OS status
that follows the OS conventions for a succesful exit.
EXIT_FAILURE (which might be in the range 1..127 but does not have
to be) produces an OS status that follows the OS conventions
for a failure.
All exit codes in the range 0..127 will produce distinguishable
OS statuses to the OS.
If the OS does not support 128 distinguishable OS statuses, then exit
status 1..N-1 will give distinguishable OS statuses where N is the number of
distinguishable OS status supported by the OS. EXIT_SUCCESS and
EXIT_FAILURE will be different if the OS supports distiguishable OS statuses.
[Should they be the same if it does not so one can test if EXIT_STATUS ==
EXIT_FAILURE ].
If you want to be more general then replace 127 above with a constant
EXIT_MAX in <limits.h> which should have minimum value of 127 unless the
OS supports less distinguishable OS statuses.
If you want to make use of OS specific features of its program exit status
system then you will always have to use OS specific functions or OS
specific knowlege. It is just as you do if you want to use any other OS
specific feature such as IPC or interactive graphics or special file formats.
--
Stephen Baynes baynes@mulsoc2.serigate.philips.nl
Philips Semiconductors Ltd
Southampton My views are my own.
United Kingdom
Technical Details
Message-ID:
<DDt13K.K22@ukpsshp1.serigate.philips.nl>Path:
arc1-ca.pugleaf.net!phcoms4.seri.philips.nl!panther!baynesReferences:
<jbundyDCw7uo.9sz@netcom.com> <danpop.807723059@rscernix> <411j5n$3va@goanna.cs.rmit.edu.au> <41b3uv$s7@caip.rutgers.edu> <dqua.809156287@dqua>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c Path: arc1-ca.pugleaf.net!phcoms4.seri.philips.nl!panther!baynes From: baynes@ukpsshp1.serigate.philips.nl (Stephen Baynes) Subject: Re: EXIT_FAILURE problem Sender: news@ukpsshp1.serigate.philips.nl (account for localnews) Message-ID: <DDt13K.K22@ukpsshp1.serigate.philips.nl> Date: Thu, 24 Aug 1995 07:35:44 GMT References: <jbundyDCw7uo.9sz@netcom.com> <danpop.807723059@rscernix> <411j5n$3va@goanna.cs.rmit.edu.au> <41b3uv$s7@caip.rutgers.edu> <dqua.809156287@dqua> Organization: Philips Semiconductors, Southampton, UK X-Newsreader: TIN [version 1.2 PL2]