Article View: comp.lang.c
Article #819Re: Taming The Switch-Statement
From: fir
Date: Mon, 26 Oct 2026 20:47
Date: Mon, 26 Oct 2026 20:47
165 lines
6503 bytes
6503 bytes
fir pisze:
> bartc pisze:
>> On 26/10/2026 19:39, fir wrote:
>>> bartc pisze:
>>
>>>>> 1 no divides (by 2 or 3)
>>>>> 2 divides by 2
>>>>> 3 divides by 3
>>>>> 4 divides by 2
>>>>> 5 no divides (by 2 or 3)
>>>>> 6 divides by 2
>>>>> 6 divides by 3
>>>>> 7 no divides (by 2 or 3)
>>>>> 8 divides by 2
>>>>> 9 divides by 3
>>>>> 10 divides by 2
>>>>> 11 no divides (by 2 or 3)
>>>>> 12 divides by 2
>>>>> 12 divides by 3
>>>>> 13 no divides (by 2 or 3)
>>>>> 14 divides by 2
>>>>> 15 divides by 3
>>>>> 16 divides by 2
>>>>> 17 no divides (by 2 or 3)
>>>>> 18 divides by 2
>>>>> 18 divides by 3
>>>>> 19 no divides (by 2 or 3)
>>>>
>>>> OK, thanks. So the pattern you're talking about is this:
>>>>
>>>> case (c1) {s1}
>>>> case (c2) {s2}
>>>> case (c3) {s3}
>>>> else {s4}
>>>>
>>>> where each of s1/s2/s3 is executed if the corresponding c1/c2/c3 is
>>>> true, independently of the others. At least one statement will be
>>>> executed in 7 of the 8 possible boolean combinations in this example.
>>>>
>>>> s4 is only executed when each of c1/c2/c3 is false. In other words:
>>>>
>>>> if (c1) {s1}
>>>> if (c2) {s2}
>>>> if (c3) {s3}
>>>> if (!c1 && !c2 && !c3) {s4}
>>>>
>>>> Assuming c1/c2/c3 are not modified by s1/s2/s3, but this is also
>>>> partly the case with your proposal.
>>>>
>>>> Or maybe it can be done like this:
>>>>
>>>> if (c1 || c2 || c3) {
>>>> s4
>>>> else if (c1) {s1)
>>>> ....
>>>>
>>>> The syntax will anyway need some work to tie all those case/if parts
>>>> together (as s2 for example could contain nested versions).
>>>>
>>>> Or you can forget about having to create a hard-to-grasp and
>>>> awkward- to-implement feature like this, and either use workarounds
>>>> like my C examples, or use another approach to the problem.
>>>>
>>>>
>>>>
>>> hahaha
>>>
>>> lol ye use worakarounds instead of simple right solution
>>
>> The right solution to what problem? It took multiple posts before you
>> even managed to explain how your proposal is supposed to behave.
>>
>> (And then tomorrow it'll probably do something else.)
>>
>>> (this solution may come in some plavours as i said before, but this
>>> or ketword for reasons mentioned is not bad)
>>
>> 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
>
>
>> Because I've not convinced it comes up often enough to be worth a
>> dedicated feature.
>>
>> Then, consider examples like this:
>>
>> case (a==b and c==d) {}
>> case (a==b and e==f) {}
>>
>> case (a<b) {}
>> case (a>=b) {}
>> case (c==d) {}
>>
>> You'll find, when converting to regular C, that detecting the case of
>> all false will mean checking all conditions, but now those will
>> contain duplicates. It is hard to cleanly express, which is a bad sign
>> as a prospective language feature.
>
>
> i dont like get what you talk here..overally this is a work for compiler
> to simplify it in output
>
>
> btw you think i should defend the things i was talking about -
> i more see its a waste of time if someone dont understand things
> it is for him if he understoods or not, i have not so much time to
> defend obvious things against the people who not care to much to
> understand things
>
> i would sy like its taking hours repairing a code that is
> good - whou would like to do it?
>
>
> generally such time spanding that you got good code and some weird
> people come nad put a bulshit its wrong and expect me to explain this is
> not its not a good time spending imo
>
> i would rather expect if some will find some 'bug ' in code then he
> first should understand it
overally instead of dwelling in this timewaste some could consider more
interesting things, for example if normal switch is like
"some true" then {} else {}
there could be considered usability of more cases
"all true" then {} else {}
"none true" then {} else {}
"only one true" then {} else {}
"only one false" then {} else {}
im not sure as to usability of this but if its usable then
it maybe can be encoded by more keywords instead of then
and else
like
case a<2 {}
case a>4 {}
case a==0 {}
case none {} //like default
case all {}
case some {}
so it seems that switch can be extended thsi way
(not sure as to usability of this)
Technical Details
Message-ID:
<11boe8t$v04r$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>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: Mon, 26 Oct 2026 21:47:26 +0100 Organization: A noiseless patient Spider Lines: 165 Message-ID: <11boe8t$v04r$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> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Mon, 26 Oct 2026 20:47:26 +0000 (UTC) Injection-Info: dont-email.me; logging-data="1015963"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ygHjQylM/I5XlByJ50kwhJa3n6/gLyGY="; 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:/W/4drgQh8+ZaSRpfbexLVD3BW4= sha256:vl4CgGheL7rbZrRd5KzP/eBK1JDHMyrairNwQ4STVyg= sha1:QnK0K3S+/2301URkYIIXZ9t95XQ= sha256:pztwcn0m2b9ZC0VDuhHadQrp9cQlK67BFQfs/6i2iik= In-Reply-To: <11bodc6$ul1k$1@dont-email.me>