Article View: comp.lang.c
Article #833Re: Taming The Switch-Statement
From: fir
Date: Mon, 26 Oct 2026 23:28
Date: Mon, 26 Oct 2026 23:28
207 lines
7098 bytes
7098 bytes
fir pisze:
> David Brown pisze:
>> On 26/10/2026 22:50, bartc wrote:
>>> On 26/10/2026 21:17, Chris M. Thomasson wrote:
>>>> On 10/26/2026 2:11 PM, bartc wrote:
>>>>> On 26/10/2026 20:32, fir wrote:
>>>>>> bartc pisze:
>>>>>
>>>>>>> OK, try a simple experiment: convert some code using your 'or'
>>>>>>> keyword to regular C syntax and post it here. Preferably on a
>>>>>>> real example.
>>>>>>>
>>>>>>
>>>>>> you cant properly convert this or/and groups to c in good way
>>>>>> becouse there is flaw in c you cannot express all needed
>>>>>> combinations generally with sole if 's and else's
>>>>>>
>>>>>> as was showed here
>>>>> There are a couple of reasons to express it in C:
>>>>>
>>>>> * To illustrate exactly how you want the semantics to work, via
>>>>> an existing language whose behaviour is well known
>>>>>
>>>>> * To highlight the problem areas
>>>>>
>>>>> For example:
>>>>>
>>>>> if (f1()) {}
>>>>> if (f2()) {}
>>>>> ...
>>>>> if (!f1() && !f2()) {}
>>>>>
>>>>> Here f1/f2 are called twice. This means making internal copies or
>>>>> setting flags.
>>>>
>>>> So you call f1 and f2, then call if (!f1() && !f2()) {}. So, that is
>>>> your choice. Not the fault of C, right?
>>>
>>> It's not the fault of C. But the C illustrates the logic of this new
>>> feature: it must only call the 'else' clause when none of the
>>> conditions are true.
>>>
>>> But if the most direct way of expressing it has this issue, then
>>> extra workarounds are needed, for example:
>>>
>>> flag=1;
>>> if f1() {flag=0;...)
>>> if f2() {flag=0;...)
>>> if (flag) {}
>>>
>>> (Note the logic here is slightly different: the else block is
>>> executed when none of the previous blocks have been entered. Because
>>> conditionals may have different values at this point. But we don't
>>> know the proper spec.)
>>>
>>> This actually isn't too bad, but in that case, why do we even need
>>> this new feature?
>>>
>>> My main problem with it is that it is unintuitive and that its
>>> use-cases are limited. It's also likely to morph into something else
>>> when fir gets bored with it.
>>>
>>>
>>
>> #define fir_switch _Bool flag = 1; {
>> #define or_if(...) } if (__VA_ARGS__) { flag = 0;
>> #define otherwise } if (!flag)
>>
>> Then Fir can write :
>>
>> fir_switch
>> or_if (x % 2 == 0) printf("\n divides by 2");
>> or_if (x % 3 == 0) printf("\n divides by 3");
>> otherwise printf("\n does not divide by 2 or 3");
>>
>> I haven't tested the defines, and I think it is a terrible idea (it
>> should at least be called "and_if"), but it comes very close to the
>> syntax and semantics Fir appears to want.
>>
>>
>
> totally no, its not also i want this i just makec conclusion if-else
> system is flawed
>
> you may ment it on some ways lik
>
> if {}
> or
> if {}
> else {}
>
> or
>
> case {}
> case {}
> otherwise {}
>
> in first case you got heneral system of logic operators applied to group
> of ifs (coz you may use not olny or but also and or not etc),
>
> in second you got like predefined keywords for "or or or" case
> (here in fact otherwise keyword means use or for cases and of 0
> evaluate otherwise)
>
> i thing you will nned a general but predefined may be also handy so
> eventually language could implement both (such as it has many forms for
> loops to increase intentions readability)
>
>
> flag is a nonsense its liek implementing else with flag
>
> int not = 1;
>
> if (a>2) {not =0; //...}
> if(not) {}
>
> ;C
>
> NOTE btw this case not only shows flaw in if rlse system but is just
> natural fom of switch (both of them i mean "if or if else" and "case
> case otherwise"..and imo thsi form is better than switch as its more
> natural its grounded -its also shows lacks of switch so it shows both
> if-else system is flawed and switch is flawed too
>
overally switch in c imo is in fact quite like goto not like if
but even if so its not general as it should bcouse if so then you should
also be jumping back
switch n //goto 1 2 3 if other goto default
case 1:
case 2:
case 4:
default:
//if so it should allow amany switches and jumps back
int s =1;
case 2:
switch s
case 1:
int b =2
case 3:
case 4:
switch b
case 5:
such switch i would more like as its much ore logical and right
but if so switch sjould be eventually named goto
(eventually goto() to make difference withh jumping under labe a and
value of (a) (though it also may staj switch for illustration here) and
case may be removed, defaul should be ranemed by other which more fits
the meaning
foo()
{
int s =1;
2:
switch s
1:
int b =2
3:
4:
switch b
other:
}
it illustrates soe things, like this c swich syntax should be
switch s;
1:
2:
3:
other:
break is not a part of it indeed it just is to make jump outside a block
*could eventually be also continue
if so some could at block at free will
switch s;
1: {2:
3: break;
other: continue; }
Technical Details
Message-ID:
<11bonn2$12f6n$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<119qf6l$2rmg3$1@dont-email.me> <11ba02r$3pl5h$1@dont-email.me> <11bnfpm$i84l$1@dont-email.me> <11bng23$iblc$1@dont-email.me> <11bngj1$ifj5$1@dont-email.me> <11bnnbg$l7i1$1@dont-email.me> <11bntk0$nsbo$1@dont-email.me> <11bnvbq$olbj$1@dont-email.me> <11bo02r$otr5$1@dont-email.me> <11bo0ul$pbso$1@dont-email.me> <11bo1bc$phlr$1@dont-email.me> <11bo86r$sgm6$1@dont-email.me> <11boaad$td13$1@dont-email.me> <11bobf0$tsad$1@dont-email.me> <11bodc6$ul1k$1@dont-email.me> <11bofl7$vjil$1@dont-email.me> <11bog1o$vhqi$2@dont-email.me> <11bohun$10fjv$1@dont-email.me> <11bokna$1192k$1@dont-email.me> <11bom51$11u3m$1@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: fir <profesor.fir@gmail.com> Newsgroups: comp.lang.c Subject: Re: Taming The Switch-Statement Date: Tue, 27 Oct 2026 00:28:33 +0100 Organization: A noiseless patient Spider Lines: 207 Message-ID: <11bonn2$12f6n$1@dont-email.me> References: <119qf6l$2rmg3$1@dont-email.me> <11ba02r$3pl5h$1@dont-email.me> <11bnfpm$i84l$1@dont-email.me> <11bng23$iblc$1@dont-email.me> <11bngj1$ifj5$1@dont-email.me> <11bnnbg$l7i1$1@dont-email.me> <11bntk0$nsbo$1@dont-email.me> <11bnvbq$olbj$1@dont-email.me> <11bo02r$otr5$1@dont-email.me> <11bo0ul$pbso$1@dont-email.me> <11bo1bc$phlr$1@dont-email.me> <11bo86r$sgm6$1@dont-email.me> <11boaad$td13$1@dont-email.me> <11bobf0$tsad$1@dont-email.me> <11bodc6$ul1k$1@dont-email.me> <11bofl7$vjil$1@dont-email.me> <11bog1o$vhqi$2@dont-email.me> <11bohun$10fjv$1@dont-email.me> <11bokna$1192k$1@dont-email.me> <11bom51$11u3m$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Mon, 26 Oct 2026 23:28:34 +0000 (UTC) Injection-Info: dont-email.me; logging-data="1129687"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Wg9wDDOVaMItGiisObKyCemvzHb7rNjA="; posting-host="524fd3863234ce524468884467e01d13" User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0 SeaMonkey/2.53.24 Cancel-Lock: sha1:a4jM2UNsUqJ+bYfIxFPG7T1B7LE= sha256:dlFHaN4GJoldqXYoHmS/yhe/vdffHglJC2WwmGOJNac= sha1:lHsNjFaocurORsZ87GWCU48T2M0= sha256:s9u6AtAJNtlpt5aGpoV06C6QUa52iGXZmzmNcAEX0Ns= In-Reply-To: <11bom51$11u3m$1@dont-email.me>