🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #3364

Re: EXIT_FAILURE problem

#3364
From: Lawrence Kirby
Date: Fri, 11 Aug 1995 12:30
46 lines
3008 bytes
In article <40escg$bud@caip.rutgers.edu> halasz@caip.rutgers.edu  writes:

>In article <Ik_SXNiSMUE48zNeor@transarc.com>, Jim_Mann@transarc.com writes
>$$$ No, the standard does not insist any such thing, nor does it insist
>$$$ that an OS that uses some other success return other than 0 is wrong.
>$$$ What the standard says is that exit(0) indicates success. On systems
>$$$ like VMS, the runtime simply translates exit(0) into the necessary
>$$$ return value indicating success.
>
>What is this but to decree that 0 is success, whatevver the OS s custom is?

This doesn't say anything about the OS. It does however determine the
action of the C runtime system. The value passed to exit is given to the
C runtime library, not the OS. The C runtime system is then required to
do whatever is necessary to return a success indication to the OS. That
might involve returning or setting an integer, a string or whatever else
the OS likes.

A very similar situation is how C deals with text files. Internally (as far
as the program is concerned) text files are lines terminated by a newline
'\n' character. The OS may store them completely differently, from
simply CR-LF terminated lines under DOS to fixed or variable length
records. Again it is up to the C runtime system to perform the appropriate
conversions.

While you are considering the return value from main also consider the
arguments passed to it. If the C systems wants to pass arguments it must
pass them in the form of aCn array of pointers to strings as defined by the
standard (if it is to be conforming). Again the runtime system will have
to perform any necessary conversions of the OS doesn't provide information
in this format.

In all of these cases (as well as many others) it is possible to write
portable code because the interfaces visible to the code are well
defined - the language provides an environment for your program which is
as independent of the OS as possible. This is as true for the value passed
to exit as anything else. In that case the meaning of most values is left
unspecified by the standard so an implementation has a great deal of leeway
to do what it likes. The standard provides the most useful definitions though,
basic success and failure indications.

-- 
-----------------------------------------
Lawrence Kirby | fred@genesis.demon.co.uk
Wilts, England | 70734.126@compuserve.com
-----------------------------------------
Technical Details
Message-ID: <808144225snz@genesis.demon.co.uk>
Path: arc1-ca.pugleaf.net!genesis.demon.co.uk!fred
References: <jbundyDCw7uo.9sz@netcom.com> <danpop.807723059@rscernix> <Ik_SXNiSMUE48zNeor@transarc.com> <40escg$bud@caip.rutgers.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!genesis.demon.co.uk!fred
From: Lawrence Kirby <fred@genesis.demon.co.uk>
Newsgroups: comp.std.c,comp.lang.c
Subject: Re: EXIT_FAILURE problem
Date: Fri, 11 Aug 95 12:30:25 GMT
Organization: none
Distribution: world
Message-ID: <808144225snz@genesis.demon.co.uk>
References: <jbundyDCw7uo.9sz@netcom.com> <danpop.807723059@rscernix> <Ik_SXNiSMUE48zNeor@transarc.com> <40escg$bud@caip.rutgers.edu>
Reply-To: fred@genesis.demon.co.uk
X-NNTP-Posting-Host: genesis.demon.co.uk
X-Newsreader: Demon Internet Simple News v1.27