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


Groups > comp.lang.c > #105852

Re: Return statement: anything goes?

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: Return statement: anything goes?
Date 2017-03-12 12:19 +0000
Organization A noiseless patient Spider
Message-ID <87innewuuq.fsf@bsb.me.uk> (permalink)
References <o9utno$5tn$1@dont-email.me> <o9v4bu$u23$1@dont-email.me> <e657889d-45ad-402b-a962-a6948ed3ec7c@googlegroups.com> <oa2mc0$eo8$1@z-news.wcss.wroc.pl> <oa393j$p0e$1@dont-email.me>

Show all headers | View raw


BartC <bc@freeuk.com> writes:

> On 12/03/2017 05:29, antispam@math.uni.wroc.pl wrote:
>> bart4858@gmail.com wrote:
>>> On Friday, 10 March 2017 21:06:54 UTC, Noob  wrote:
>>>
>>>> Why do you expect an error for B5?
>>>
>>> I should have used 'if (x)' rather than 'if (1)'. I'll test again once I get my machine back (currently used for gaming).
>>>
>>> (My own code would test that an explicit 'return expr;' is encountered before running into the closing '}'. A closing 'if' would need both branches and each would need to end with 'return'.)
>>>
>>
>> What about (assuming usual declaration of 'open' and 'exit'):
>>
>> int
>> do_open(const char * fname)
>> {
>>    int fd = open(fname, O_RDONLY);
>>    if (fd < 0) {
>>        exit(1);
>>    } else {
>>        return fd;
>>    }
>> }
>
> I checked the equivalent in other language where I implement this
> check, and that works (exit(1) is written 'stop 1', and 'stop' is
> acceptable too).

That might be to miss antispam's point.  exit happens to be known to the
compiler but any function call it (or call a function that calls it...):

  if (C)
      print_error_and_exit("hey!);
  else return 42;

C11 has the _Noreturn function specifier.

<snip>
-- 
Ben.

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


Thread

Return statement: anything goes? BartC <bc@freeuk.com> - 2017-03-10 19:13 +0000
  Re: Return statement: anything goes? John Bode <jfbode1029@gmail.com> - 2017-03-10 11:59 -0800
    Re: Return statement: anything goes? Keith Thompson <kst-u@mib.org> - 2017-03-10 12:34 -0800
  Re: Return statement: anything goes? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-03-10 20:17 +0000
    Re: Return statement: anything goes? bart4858@gmail.com - 2017-03-10 13:17 -0800
      Re: Return statement: anything goes? Ian Collins <ian-news@hotmail.com> - 2017-03-11 10:30 +1300
      Re: Return statement: anything goes? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-03-11 01:25 +0000
        Re: Return statement: anything goes? BartC <bc@freeuk.com> - 2017-03-11 12:11 +0000
          Re: Return statement: anything goes? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-03-11 14:57 +0000
            Re: Return statement: anything goes? BartC <bc@freeuk.com> - 2017-03-11 16:31 +0000
              Re: Return statement: anything goes? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-03-11 17:47 +0000
                Re: Return statement: anything goes? BartC <bc@freeuk.com> - 2017-03-11 17:57 +0000
                Re: Return statement: anything goes? jameskuyper@verizon.net - 2017-03-11 10:59 -0800
                Re: Return statement: anything goes? BartC <bc@freeuk.com> - 2017-03-11 19:34 +0000
                Re: Return statement: anything goes? jameskuyper@verizon.net - 2017-03-11 11:59 -0800
                Re: Return statement: anything goes? supercat@casperkitty.com - 2017-03-11 12:26 -0800
                Re: Return statement: anything goes? supercat@casperkitty.com - 2017-03-11 12:22 -0800
                Re: Return statement: anything goes? jameskuyper@verizon.net - 2017-03-11 12:42 -0800
                Re: Return statement: anything goes? supercat@casperkitty.com - 2017-03-11 13:01 -0800
                Re: Return statement: anything goes? Gordon Burditt <gordon@hammy.burditt.org> - 2017-03-13 16:25 -0500
            Re: Return statement: anything goes? Gareth Owen <gwowen@gmail.com> - 2017-03-11 16:43 +0000
              Re: Return statement: anything goes? BartC <bc@freeuk.com> - 2017-03-11 18:13 +0000
                Re: Return statement: anything goes? BartC <bc@freeuk.com> - 2017-03-11 18:27 +0000
          Re: Return statement: anything goes? gordonb.rlpr3@burditt.org (Gordon Burditt) - 2017-03-13 16:18 -0500
        Re: Return statement: anything goes? supercat@casperkitty.com - 2017-03-11 12:44 -0800
      Re: Return statement: anything goes? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2017-03-11 07:43 -0800
        Re: Return statement: anything goes? BartC <bc@freeuk.com> - 2017-03-11 18:34 +0000
          Re: Return statement: anything goes? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2017-03-11 10:43 -0800
  Re: Return statement: anything goes? Keith Thompson <kst-u@mib.org> - 2017-03-10 12:27 -0800
  Re: Return statement: anything goes? Noob <root@127.0.0.1> - 2017-03-10 22:06 +0100
    Re: Return statement: anything goes? bart4858@gmail.com - 2017-03-10 13:26 -0800
      Re: Return statement: anything goes? antispam@math.uni.wroc.pl - 2017-03-12 05:29 +0000
        Re: Return statement: anything goes? BartC <bc@freeuk.com> - 2017-03-12 10:52 +0000
          Re: Return statement: anything goes? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-03-12 12:19 +0000
            Re: Return statement: anything goes? BartC <bc@freeuk.com> - 2017-03-12 12:51 +0000

csiph-web