| Deutsch English Français Italiano |
|
<vgn0vl$3kr82$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: Janis Papanagnou <janis_papanagnou+ng@hotmail.com> Newsgroups: comp.lang.c Subject: Re: else ladders practice Date: Sat, 9 Nov 2024 07:54:44 +0100 Organization: A noiseless patient Spider Lines: 37 Message-ID: <vgn0vl$3kr82$1@dont-email.me> References: <3deb64c5b0ee344acd9fbaea1002baf7302c1e8f@i2pn2.org> <vg0t3j$2ruor$1@dont-email.me> <78eabb4054783e30968ae5ffafd6b4ff2e5a5f17@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> <vg8a84$euka$1@dont-email.me> <vg8koq$gpsg$1@dont-email.me> <vgat50$112jp$1@dont-email.me> <vgb8if$13ioj$1@dont-email.me> <vgbhkt$155v2$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Date: Sat, 09 Nov 2024 07:54:46 +0100 (CET) Injection-Info: dont-email.me; posting-host="3c8adf7a738086e8d1f465f4520e5df9"; logging-data="3828994"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18JLBVE+T1CrZfjXt74Wpk5" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 Cancel-Lock: sha1:6zMst3Du1jUTMEKeGwW4EYLD4qc= In-Reply-To: <vgbhkt$155v2$1@dont-email.me> X-Enigmail-Draft-Status: N1110 Bytes: 3420 On 04.11.2024 23:25, David Brown wrote: > > If you have a function (or construct) that returns a correct value for > inputs 1, 2 and 3, and you never pass it the value 4 (or anything else), > then there is no undefined behaviour no matter what the code looks like > for values other than 1, 2 and 3. If someone calls that function with > input 4, then /their/ code has the error - not the code that doesn't > handle an input 4. Well, it's a software system design decision whether you want to make the caller test the preconditions for every function call, or let the callee take care of unexpected input, or both. We had always followed the convention to avoid all undefined situations and always define every 'else' case by some sensible behavior, at least writing a notice into a log-file, but also to "fix" the runtime situation to be able to continue operating. (Note, I was mainly writing server-side software where this was especially important.) That's one reason why (as elsethread mentioned) I dislike 'else' to handle a defined value; I prefer an explicit 'if' and use the else for reporting unexpected situations (that practically never appear, or, with the diagnostics QA-evaluated, asymptotically disappearing). (For pure binary predicates there's no errors branch, of course.) Janis PS: One of my favorite IT-gotchas is the plane crash where the code specified landing procedure functions for height < 50.0 ft and for height > 50.0 ft conditions, which mostly worked since the height got polled only every couple seconds, and the case height = 50.0 ft happened only very rarely due to the typical descent characteristics during landing.