Deutsch   English   Français   Italiano  
<86v7x5thjt.fsf@linuxsc.com>

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: Tim Rentsch <tr.17687@z991.linuxsc.com>
Newsgroups: comp.lang.c
Subject: Re: else ladders practice
Date: Sat, 02 Nov 2024 15:08:38 -0700
Organization: A noiseless patient Spider
Lines: 61
Message-ID: <86v7x5thjt.fsf@linuxsc.com>
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>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Date: Sat, 02 Nov 2024 23:08:39 +0100 (CET)
Injection-Info: dont-email.me; posting-host="d09aaab7860833338ed3364fdef11758";
	logging-data="4184527"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18RaLlZTQq6nydYWVk9jTUq7KUgatPuC4Y="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:9ZSZ28RjEfQ0GWBpEHMFDHXLFzg=
	sha1:gaLoMpVfcHJgPDR8PovPgrsaGUw=
Bytes: 3648

Bart <bc@freeuk.com> writes:

> On 02/11/2024 11:41, David Brown wrote:
>
>> On 01/11/2024 20:47, Bart wrote:
>>
>>> On 01/11/2024 18:47, David Brown wrote:
>>>
>>>> On 01/11/2024 19:05, Bart wrote:
>>>>
>>>>> On 01/11/2024 17:35, David Brown wrote:
>>>
>>>>>>
>>>>>> What you have written here is all correct, but a more common
>>>>>> method would be to avoid having three printf's :
>>>>>>
>>>>>> void shout_a_number(int n) {
>>>>>> printf( (const char* []) { "ONE", "TWO", "THREE" } [n] );
>>>>>> }
>>>>>>
>>>>>> That's more likely to match what people would want.
>>>>>
>>>>> I was also trying to show that all elements are evaluated, so
>>>>> each has to have some side-effect to illustrate that.
>>>>
>>>> Fair enough.
>>>>
>>>>> A true N-way-select construct (C only really has ?:) would
>>>>> evaluate only one, and would deal with an out-of-range condition.
>>>>
>>>> That's a matter of opinion and design choice, rather than being
>>>> requirements for a "true" select construct.
>>>
>>> I don't think it's just opinion.
>>
>> Yes, it is.

I believe the phrase "N-way-select" would be understood by
most people to mean either exactly one or at most one out
of the N choices is put into effect.  Saying it's just an
opinion is idiotic.  We may not know how different people
would understand it, but how they understand it is something
that can be determined objectively, simply by asking them.

> Then we disagree on what 'multi-way' select might mean.  I think it
> means branching, even if notionally, on one-of-N possible code paths.
>
> The whole construct may or may not return a value.  If it does, then
> one of the N paths must be a default path.

Alternatively there could be an implicit default value.  For
example, a hypothetical construct

   ( p; q; r; s; t )

where all of the variables are pointers, might return the first
pointer than is non-null, or a null pointer if all of them are
null (with an obvious generalization if the result expressions
and gating boolean expressions are distinct).  Isn't this how
'cond' in Lisp works?  Return the first expression whose guard
is non-nil, or nil if all the guards are nil.