Deutsch English Français Italiano |
<vgil5i$2mr19$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Bart <bc@freeuk.com> Newsgroups: comp.lang.c Subject: Re: else ladders practice Date: Thu, 7 Nov 2024 15:08:34 +0000 Organization: A noiseless patient Spider Lines: 33 Message-ID: <vgil5i$2mr19$1@dont-email.me> References: <3deb64c5b0ee344acd9fbaea1002baf7302c1e8f@i2pn2.org> <vg2g37$37mh3$1@dont-email.me> <6724CFD2.4030607@grunge.pl> <vg2llt$38ons$1@dont-email.me> <2491a699388b5891a49ef960e1ad8bb689fdc2ed@i2pn2.org> <b681ee05856e165c26a5c29bf42a8d9d53843d6d@i2pn2.org> <vg2ttn$3a4lk$1@dont-email.me> <vg33gs$3b8n5$1@dont-email.me> <vg358c$3bk7t$1@dont-email.me> <vg37nr$3bo0c$1@dont-email.me> <vg3b98$3cc8q$1@dont-email.me> <vg5351$3pada$1@dont-email.me> <vg62vg$3uv02$1@dont-email.me> <vgd3ro$2pvl4$1@paganini.bofh.team> <vgd6jh$1hmjc$1@dont-email.me> <vge7bt$1o57r$1@dont-email.me> <vgfvne$25kug$1@dont-email.me> <vgibf8$2l858$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Thu, 07 Nov 2024 16:08:34 +0100 (CET) Injection-Info: dont-email.me; posting-host="ec686777c96cc376bc9818100d47f072"; logging-data="2845737"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18QRBBD/7nwICBacV5PsbV5" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:HY2bkwy5EPI6ohbn4ZSpEuXaCyY= Content-Language: en-GB In-Reply-To: <vgibf8$2l858$1@dont-email.me> Bytes: 2744 On 07/11/2024 12:23, Bart wrote: > On 06/11/2024 14:50, David Brown wrote: >> C gets it right here. There is no need for a return type when there >> is no return > > There is no return for only half the function! A function with a return > type is a function that CAN return. If it can't ever return, then make > it a procedure. > > Take this function where N can never be zero; is this the right way to > write it in C: > > int F(int N) { > if (N==0) unreachable(); > return abc/N; // abc is a global with value 100 > } > > If doesn't look right. If I compile it with gcc (using > __builtin_unreachable), and call F(0), then it crashes. So it doesn't do > much does it?! It looks like it needs 'else' here. If I put that in, then F(0) returns either 0 or 1, so it returns garbage, whether or not 'unreachable' is used in the branch. So I'm struggling to see the point of it. Is it just to quieten the 'reaches end of non-void function' warning when used before the final '}'? In any case, 'unreachable' is a misnomer. 'shouldnt_be_reachable' is more accurate.