Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #108182

Re: main return value is helpfull?

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: main return value is helpfull?
Date 2017-04-16 14:41 -0700
Organization None to speak of
Message-ID <ln8tn0t4hw.fsf@kst-u.example.com> (permalink)
References <7e8ec0c1-c5ac-4657-8c7f-5c26c5bf0c74@googlegroups.com> <a9769738-bba6-4f5a-92c5-d7050edfa5d6@googlegroups.com>

Show all headers | View raw


supercat@casperkitty.com writes:
[...]
> The Standard is relatively silent as to how implementations should use the
> return value, except for the general notion that if an environment provides a
> means by which programs can return a value to indicate success, failure, or
> other such status, it should indicate success if main() returns 0 or code
> calls exit(0) and failure if main() returns 1 or code calls exit(1).  If the
> environment can handle more than 2 values, returning values other than 0 or 1
> may be useful, but the Standard doesn't impose requirements upon how they
> should work (e.g. if an environment would normally use negative values to
> indicate failure and positive values to indicate success, it may be unclear
> what "return 4;" should mean.

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.

Values other than 0, EXIT_SUCCESS, or EXIT_FAILURE might have
implementation-defined meanings.  For example, many programs on
Unix-like systems use other values to convey more information to the
caller.  The grep command uses 1 to indicate that no match was found,
and 2 to indicate some other error; curl currently defines distinct
meanings for exit codes from 0 to 92.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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