Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #108230
| From | Lew Pitcher <lew.pitcher@digitalfreehold.ca> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: main return value is helpfull? |
| Followup-To | comp.lang.c |
| Date | 2017-04-17 13:57 -0400 |
| Organization | The Pitcher Digital Freehold |
| Message-ID | <od2vg1$m5o$1@dont-email.me> (permalink) |
| References | <7e8ec0c1-c5ac-4657-8c7f-5c26c5bf0c74@googlegroups.com> <a9769738-bba6-4f5a-92c5-d7050edfa5d6@googlegroups.com> |
Followups directed to: comp.lang.c
supercat@casperkitty.com wrote:
> On Sunday, April 16, 2017 at 2:51:24 PM UTC-5, esmaeel ensanimehr wrote:
>> but is there any useful example for main() return value?
>>
>> for example:
>> int c = main();
>
> Many environments from which C programs can be run provide a means via
> which
> they can indicate success or failure to the calling process. When running
> a sequence of programs via shell script (Unix), batch file (DOS/Windows),
> or other such means, it can be helpful to have the process stop as soon as
> any part of it fails.
[snip]
> In Unix, the default
> behavior would from what I understand be to stop script processing if any
> program returns a non-zero value *unless* a special syntax is used to
> indicate that errors should not terminate processing.
Nonsense.
Unix shell scripting languages have a well-defined behaviour wrt evaluating
the return value from a process.
1) Unless explicitly tested, the return value (no matter what it is) is
ignored.
2) When explicitly tested, a return value of zero (0) is treated as an
indication of success. A non-zero value is /not/ an explicit indication
of failure.
3) The script may test for a specific return value, and take action
accordingly.
Consequently, the following is valid...
cat >test_1.c <<EOF
int main(void) { return 0; }
EOF
if cc -o test_1 test_1.c
then
test_1
else
echo Compilation returned a non-zero rc
fi
where cat, cc, and test_1 are all programs that return "return values" to
the script.
[snip]
--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request
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