delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/10/25/05:46:19

Message-ID: <39F697DB.E821B984@antlimited.com>
Date: Wed, 25 Oct 2000 09:20:43 +0100
From: Richard Heathfield <richard AT antlimited DOT com>
X-Mailer: Mozilla 4.72 [en] (X11; U; Linux 2.2.14-5.0 i686)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: alt.comp.lang.learn.c-c++,comp.os.msdos.djgpp,comp.programming
Subject: Re: Undertaking a programming journey
References: <MOqE5.2173$W31 DOT 29870 AT news1 DOT online DOT no> <8scg36$gsm$1 AT nnrp1 DOT deja DOT com> <39E9CF07 DOT 785C0C0F AT eton DOT powernet DOT co DOT uk> <8scls9$kth$1 AT nnrp1 DOT deja DOT com> <rgnjusgvadc5q9d53jticrrgdthc9af3lv AT 4ax DOT com> <39E9FAD5 DOT DE1FDAE4 AT eton DOT powernet DOT co DOT uk> <8sdrub$h7u$1 AT nnrp1 DOT deja DOT com> <39EAA40B DOT 31B0CA89 AT eton DOT powernet DOT co DOT uk> <39f5ff14 DOT 90960240 AT news DOT esatclear DOT ie> <8t4vo5$1lp$1 AT nntp9 DOT atl DOT mindspring DOT net>
NNTP-Posting-Host: fb-ext.ant.co.uk
X-Trace: 25 Oct 2000 09:16:57 GMT, fb-ext.ant.co.uk
Lines: 52
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Mike Wahler wrote:
> 
> Russell Wallace <rwallace AT esatclear DOT ie> wrote in message
> news:39f5ff14 DOT 90960240 AT news DOT esatclear DOT ie...
> > On Mon, 16 Oct 2000 07:45:31 +0100, Richard Heathfield
> > <binary AT eton DOT powernet DOT co DOT uk> wrote:
> > >Schildt is probably the primary reason that so many C programmers think
> > >exit(1) is portable.
> >
> > Don't think I've read any of Schildt's books, but I'll admit I always
> > did think exit(1) was portable.  Why isn't it, and what should be used
> > instead?
> 
> The only return (exit) values defined by the standard are:
> 
> a) EXIT_SUCCESS
> b) EXIT_FAILURE
> c) The integer value zero (0)
> 
> The 'EXIT_' macros are defined in
> <stdlib.h>

Exactly right. To clarify a bit for the OP, though: exit(1) is portable
in the sense that it will always return 1 to the calling process (just
like return 1; in main(), to which this discussion applies also!); what
is /not/ portable is the /semantics/ - i.e. what the code /means/.
Different return codes mean different things to different operating
systems. For example, there's one OS that interprets even return codes
as failures, and odd return codes as successes! (Is it VMS?)

Now, if you return 0 or EXIT_SUCCESS from your program, either via a
return from main() or from exit(), a conforming C compiler guarantees
that it will translate that value into the value interpreted by the OS
as "success". If you return EXIT_FAILURE, the compiler guarantees that
it will translate /that/ value into the value interpreted by the OS as
"failure". Thus, in the case of VMS(?), the compiler will translate
"return 0;" into "return some odd number or other" for you, and "return
EXIT_FAILURE;" into "return some odd number or other" (and,
interestingly, it need not be the /same/ odd number as for "return 0"!
(although it probably will be, I guess)). Similarly, a VMS(?) C compiler
would ensure that "return EXIT_FAILURE" returned an even number to the
OS.

No other values than the ones cited are semantically portable.

I hope that clarifies matters for the OP.

-- 
Richard Heathfield
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R Answers: http://users.powernet.co.uk/eton/kandr2/index.html

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019