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


Groups > comp.lang.c > #151825

Re: This statement may fall through - how?

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: This statement may fall through - how?
Date 2020-04-30 13:42 +0100
Organization A noiseless patient Spider
Message-ID <87y2qd5en1.fsf@bsb.me.uk> (permalink)
References (2 earlier) <r8e3dk$otr$2@news.xmission.com> <r8e3nj$6q3$1@news.albasani.net> <r8e49j$iun$1@dont-email.me> <875zdh72rs.fsf@nosuchdomain.example.com> <r8ecn8$asi$1@dont-email.me>

Show all headers | View raw


James Harris <james.harris.1@gmail.com> writes:

> On 30/04/2020 10:15, Keith Thompson wrote:
>> James Harris <james.harris.1@gmail.com> writes:
<cut>
>>> If printing a usage message on request a return 0 could be
>>> correct. But if the usage message is printed due to parameter errors
>>> then one could return 1 (or perhaps some other nonzero) ... from main.
>>
>> Or EXIT_FAILURE.
>
> I didn't know that existed but it and EXIT_SUCCESS are curious
> definitions because while a good use of header files is to ensure that
> constants agree between C modules what main returns to may not be C.
>
> If whatever called main was not written in C it may not have been able
> to parse stdlib.h or even be built against the same versions of such
> constants. Therefore, unless there is a way for the caller to find out
> what EXIT_FAILURE and EXIT_SUCCESS the main function was built with
> there would strictly speaking be no way for the caller to test for
> exit success or failure!

They are designed so that the C programmer does not need to know how the
hosting system interprets the value returned by main.  If that
(basically the "OS") is what you mean by "whatever called main" then
they do the job perfectly adequately.  But if you are talking about some
other way in which main is called, I don't see how anything in the C
standard could possible help.

> IOW, it may be best to return 0 or 1.

If the OS interprets all return values less that 256 as "success" then
returning 1 does not signal a failure.

-- 
Ben.

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


Thread

This statement may fall through - how? mathog <mathog@caltech.edu> - 2020-04-29 17:18 -0700
  Re: This statement may fall through - how? Ian Collins <ian-news@hotmail.com> - 2020-04-30 12:32 +1200
    Re: This statement may fall through - how? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-29 18:03 -0700
      Re: This statement may fall through - how? Ian Collins <ian-news@hotmail.com> - 2020-04-30 14:01 +1200
      Re: This statement may fall through - how? mathog <mathog@caltech.edu> - 2020-04-30 13:29 -0700
        Re: This statement may fall through - how? Spiros Bousbouras <spibou@gmail.com> - 2020-04-30 21:09 +0000
          Re: This statement may fall through - how? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-30 15:19 -0700
          Re: This statement may fall through - how? mathog <mathog@caltech.edu> - 2020-04-30 16:21 -0700
            Re: This statement may fall through - how? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-30 17:27 -0700
            Re: This statement may fall through - how? Ian Collins <ian-news@hotmail.com> - 2020-05-01 12:44 +1200
              Re: This statement may fall through - how? mathog <mathog@caltech.edu> - 2020-05-01 10:28 -0700
                Re: This statement may fall through - how? chad <cdalten@gmail.com> - 2020-05-01 12:43 -0700
  Re: This statement may fall through - how? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-04-29 17:58 -0700
  Re: This statement may fall through - how? scott@slp53.sl.home (Scott Lurndal) - 2020-04-30 01:25 +0000
    Re: This statement may fall through - how? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-29 18:37 -0700
  Re: This statement may fall through - how? Bonita Montero <Bonita.Montero@gmail.com> - 2020-04-30 10:33 +0200
    Re: This statement may fall through - how? gazelle@shell.xmission.com (Kenny McCormack) - 2020-04-30 08:48 +0000
      Re: This statement may fall through - how? Bonita Montero <Bonita.Montero@gmail.com> - 2020-04-30 10:54 +0200
        Re: This statement may fall through - how? James Harris <james.harris.1@gmail.com> - 2020-04-30 10:03 +0100
          Re: This statement may fall through - how? Bonita Montero <Bonita.Montero@gmail.com> - 2020-04-30 11:08 +0200
          Re: This statement may fall through - how? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-30 02:15 -0700
            Re: This statement may fall through - how? James Harris <james.harris.1@gmail.com> - 2020-04-30 12:27 +0100
              Re: This statement may fall through - how? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-04-30 13:42 +0100
              Re: This statement may fall through - how? James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-04-30 10:26 -0400
                Re: This statement may fall through - how? James Harris <james.harris.1@gmail.com> - 2020-04-30 17:43 +0100
                Re: This statement may fall through - how? James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-04-30 13:01 -0400
                Re: This statement may fall through - how? Spiros Bousbouras <spibou@gmail.com> - 2020-04-30 17:34 +0000
                Re: This statement may fall through - how? Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2020-04-30 13:53 -0400
                Re: This statement may fall through - how? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-30 13:21 -0700
                Re: This statement may fall through - how? scott@slp53.sl.home (Scott Lurndal) - 2020-04-30 17:54 +0000
                Re: This statement may fall through - how? chad <cdalten@gmail.com> - 2020-04-30 10:55 -0700
              Re: This statement may fall through - how? Richard Damon <Richard@Damon-Family.org> - 2020-04-30 10:30 -0400
        Re: This statement may fall through - how? gazelle@shell.xmission.com (Kenny McCormack) - 2020-04-30 09:10 +0000
          Re: This statement may fall through - how? Bonita Montero <Bonita.Montero@gmail.com> - 2020-04-30 11:18 +0200
            Re: This statement may fall through - how? mathog <mathog@caltech.edu> - 2020-04-30 13:13 -0700

csiph-web