Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #108189
| From | Andrey Tarasevich <andreytarasevich@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: main return value is helpfull? |
| Date | 2017-04-16 18:58 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <od17ba$hn4$1@dont-email.me> (permalink) |
| References | <7e8ec0c1-c5ac-4657-8c7f-5c26c5bf0c74@googlegroups.com> <a9769738-bba6-4f5a-92c5-d7050edfa5d6@googlegroups.com> <ln8tn0t4hw.fsf@kst-u.example.com> |
On 4/16/2017 2:41 PM, Keith Thompson wrote: > > Returning 0 does indicate success, but the standard doesn't guarantee > that exit(1) will indicate failure. It does on many systems, but in > particular Open VMS uses odd results for success and even results for > failure (with 0 denoting success as a special case). That's why we have > the macros EXIT_SUCCESS and EXIT_FAILURE. > > EXIT_SUCCESS is almost always defined as 0, but there's no requirement > that EXIT_SUCCESS==0, as long as both values denote success. > The "as long as both values denote success" remark appears to be unnecessary in this case. The specification of 'exit' states the following: "[...] 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. [...]" This basically says that such status values as '0', 'EXIT_SUCCESS' and 'EXIT_FAILURE' are given special treatment. They are not necessarily passed to the host environment _directly_. They are _translated_ into the proper host-specific status values indicating "success" and "failure". In other words, conceptually, the host environment never sees the actual value of 'EXIT_SUCCESS'. It does not matter what (if anything) the value of 'EXIT_SUCCESS' means in host environment. It is only the implementation that sees the actual values of 'EXIT_SUCCESS'. And it guarantees that 'exit(EXIT_SUCCESS)' will return to the host a [possibly different] status code indicating "success". If some host environment uses values of '-1' and '255' to indicate "failure" and "success", it still perfectly possible to have 'EXIT_FAILURE' defined as '1' and 'EXIT_SUCCESS' defined as '0', as long as 'exit' remembers to translate '1' to '-1' and '0' to '255'. -- Best regards, Andrey Tarasevich
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
main return value is helpfull? esmaeel ensanimehr <eensanimehr@gmail.com> - 2017-04-16 12:51 -0700
Re: main return value is helpfull? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-04-16 21:11 +0100
Re: main return value is helpfull? supercat@casperkitty.com - 2017-04-16 13:19 -0700
Re: main return value is helpfull? Keith Thompson <kst-u@mib.org> - 2017-04-16 14:41 -0700
Re: main return value is helpfull? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2017-04-16 18:58 -0700
Re: main return value is helpfull? Manfred <noname@invalid.add> - 2017-04-17 19:34 +0200
Re: main return value is helpfull? Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2017-04-17 13:57 -0400
Re: main return value is helpfull? Keith Thompson <kst-u@mib.org> - 2017-04-17 12:19 -0700
Re: main return value is helpfull? Manfred <noname@invalid.add> - 2017-04-18 13:03 +0200
Re: main return value is helpfull? Keith Thompson <kst-u@mib.org> - 2017-04-18 09:29 -0700
Re: main return value is helpfull? gordonb.xo0e7@burditt.org (Gordon Burditt) - 2017-04-17 04:40 -0500
Re: main return value is helpfull? Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2017-04-18 21:39 -0600
csiph-web