🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #260

Re: Taming The Switch-Statement

#260
From: bart
Date: Mon, 12 Oct 2026 10:42
105 lines
4548 bytes
On 12/10/2026 06:22, David Brown wrote:
> On 12/10/2026 00:05, bart wrote:

>> So you don't really get it. That's fine.
>>
> 
> So now you can drop it, along with all your other complaints about the C 
> language and tools people use with it?

My opinions haven't changed at all. KT doesn't care because he doesn't 
understand the importance of having properly designed features. Probably 
he hasn't been involved in having to process somebody else's source code 
or having to translate it or port it.

I have an old tool which /visualises/ C source code by trying to express 
it in my syntax. It is not a formal transpiler: the semantics are not 
translated, just the shape of the code.

Still, the transformation is usually startlingly clear compared with the 
original. Anyway I applied it to two examples, first:

     switch (a) {
     case 1: 10; break;
     case 2: 20; break;
     default: 30;
     }

The output is:

     switch a
     when 1 then
         10
     when 2 then
         20
     else
         30
     end

Notice there are no breaks (which don't exist in my syntax). This is the 
second:

     switch (a) {
     default:
         if (b) {
             case 1: 10; break;
             case 2: 20; break;
         }
     }

The ") {" had to present as the tool requires the switch body to be a 
compound statement. The output is:

     switch a
     else
         if b then

         end
     end

This generated error messages about case-statement not being supported 
(being out of place).

But it doesn't look right does it?. Maybe a better version could express 
switch using gotos and arrays of label-pointers, but this would be 
disastrous for examples like the first.

I then tried Duff's example for fun, and it produced this:

     switch count rem 8
     when 0 then
         to^ := (from++)^
         fallthrough
     when 7 then
         to^ := (from++)^
         fallthrough
     when 6 then
         to^ := (from++)^
         fallthrough
     when 5 then
         to^ := (from++)^
         fallthrough
     when 4 then
         to^ := (from++)^
         fallthrough
     when 3 then
         to^ := (from++)^
         fallthrough
     when 2 then
         to^ := (from++)^
         fallthrough
     when 1 then
         to^ := (from++)^
     end

I'm surprised that it detected fall-through, but probably only in the 
simplest cases (non-empty block not ending in 'break').

'fallthrough' doesn't exist in my syntax so here it must just be a hint.


> Alternatively, you are free to write proposals for the C standards 
> committee, or take part in their discussions, aiming to actually change 
> the things you so passionately insist need fixing.
I'll be long dead before anything happens. It's taken most of my 
lifetime before even a no-brainer like binary literals became official.
Technical Details
Message-ID: <11aidi3$3gbu4$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-mail
References: <119qf6l$2rmg3$1@dont-email.me> <11ac0mi$19kfd$1@dont-email.me> <11ac2jv$1a84t$1@dont-email.me> <11ac783$1bkuo$1@kst.eternal-september.org> <11ad5eq$1l8hg$1@dont-email.me> <11aehqg$24k8m$3@kst.eternal-september.org> <11aenps$27sq7$1@dont-email.me> <11aetqv$29hmu$1@kst.eternal-september.org> <11afrfq$2j2o6$1@dont-email.me> <11agtkb$30q22$1@kst.eternal-september.org> <11ah16h$320sj$2@dont-email.me> <11ahqpu$38ir0$3@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: bart <bc@freeuk.com>
Newsgroups: comp.lang.c
Subject: Re: Taming The Switch-Statement
Date: Mon, 12 Oct 2026 11:42:10 +0100
Organization: A noiseless patient Spider
Lines: 105
Message-ID: <11aidi3$3gbu4$1@dont-email.me>
References: <119qf6l$2rmg3$1@dont-email.me> <11ac0mi$19kfd$1@dont-email.me>
 <11ac2jv$1a84t$1@dont-email.me> <11ac783$1bkuo$1@kst.eternal-september.org>
 <11ad5eq$1l8hg$1@dont-email.me> <11aehqg$24k8m$3@kst.eternal-september.org>
 <11aenps$27sq7$1@dont-email.me> <11aetqv$29hmu$1@kst.eternal-september.org>
 <11afrfq$2j2o6$1@dont-email.me> <11agtkb$30q22$1@kst.eternal-september.org>
 <11ah16h$320sj$2@dont-email.me> <11ahqpu$38ir0$3@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 12 Oct 2026 10:42:12 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="3682244"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/wDF9oCNypghOacUZO7HGh"; posting-host="77c9fe16ce3505b18aae67dd9ba4b8ee"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:rqIkXmmov1TRoR3n+Qm8SwtVoHo= sha256:pI1nEpsg4vkEHQ7IOoZ2alHXw40BQf2wjJHWgH2INDQ=
	sha1:2H6As70oy1XzjfvB4Tv9Vwlo3dM= sha256:K7efKKJXQXQ0VojukIRNu1pj14cRf3T7PThGbMR4HzM=
Content-Language: en-GB
In-Reply-To: <11ahqpu$38ir0$3@dont-email.me>