Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Compilation problems??

Re: Compilation problems??

From: Chris Engebretson <engebret_at_sg1.cr.usgs.gov>
Date: 1997/08/15
Message-ID: <EEyJB2.Ex4@igsrsparc2.er.usgs.gov>#1/1

In article <33F39B9C.5E4C_at_ici.net>, Alicia Carla Longstreet <carla_at_ici.net> writes:
|> Chris Engebretson wrote:
|> >
|> > In article <33F359DD.4855_at_ici.net>, Alicia Carla Longstreet <carla_at_ici.net> writes:
|> >
|> > |> There is NOTHING in the standard that requires a program to return
|> > |> either EXIT_SUCCESS or EXIT_FAILURE, the Standard allows ANY INTEGER
|> > |> VALUE to be returned, with either exit() or a simple return.
|> >
|> > However a program which exits with a status other than 0, EXIT_SUCCESS,
|> > or EXIT_FAILURE is not a strictly-conforming C program. The behavior
|> > of exit statuses not mentioned above is implementation-defined, i.e,
|> > on one platform "exit(1);" might indicate success, on another it might
|> > indicate failure, and on yet another it might even indicate that the
|> > program "almost worked."
|>
|> Which is patently absurd. When I write a program, I, not the standard,
|> not you or anybody else, decide what the exit codes mean. Exit codes
|> often specify what went wrong, or possibly, most any exit code is a code
|> for sucess. The Standard defines three exit codes to be used when the
|> programmer has no desire or need to provide exit codes of his/her own
|> specification.

Nope. The standard does not guarantee that return or exit() can represent any status other than success or failure. Please do not let your experience with a certain platform(s) lull you into reading more into the standard than is actually there.

|> Exit codes are NEVER implementation defined, they are ALWAYS defined by
|> the programmer and should be specified in the documentation.

Exit codes are NEVER implementation defined?

    "Finally, control is returned to the host environment. If the

     value of status is zero or EXIT_SUCCESS, an *implementation-
     defined* form of the status 'successful termination' is 
     returned.  If the value of status is EXIT_FAILURE, an
     *implementation-defined* form of the status 'unsuccessful
     termination' is returned.  Otherwise, the status is
     *implementation-defined.*" ISO/IEC 9899:1990, 7.10.4.3

Unless I'm counting wrong, the term "implementation defined" appears three times in the above explanation from the standard. You are thus officially outranked. :-)

|> If I write a program and decide that exit(99) indicates failure due to
|> an inability to allocate sufficient memory for a data object, that is
|> EXACTLY what an exit code of 99 will mean ON EVERY SINGLE PLATFORM/OS
|> THAT I CHOOSE TO PORT MY PROGRAM TO.
Pure nonsense. Can you back this up with any documentation? More specifically, can you state where the standard says that "exit(99);" will provide the caller with a return code of 99? Save yourself some time and don't bother; the standard guarantees no such thing.

An implementation may decide to, for example, treat every odd status passed to exit() as an indication of failure, and every even one as an indication of success(). It may choose to treat every status *except* 99 as success, and treat 99 as an error indicator. Now certainly, these are silly examples, but the point is that the standard does not rule them out.

You seem to be having the misconception that whatever is passed to exit() is what is passed back as the return code to the OS/caller/ what-have-you. This is *not* true. On a machine where 1 indicates success, C programs must still return 0. It is up to the implementation to do the "translation" to ensure that the platform's expectations for return codes are met sensibly.

Regards,

-- 
Chris Engebretson --- Hughes STX Corporation | Ph#: (605)594-6829
USGS EROS Data Center, Sioux Falls, SD 57198 | Fax: (605)594-6490
Landsat 7 IAS Engineering Team -- http://ltpwww.gsfc.nasa.gov/IAS
http://edcwww.cr.usgs.gov/        mailto:engebret@sg1.cr.usgs.gov
Opinions here are not those of Hughes Aircraft, STX, or the USGS.
Received on Fri Aug 15 1997 - 00:00:00 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US