🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #501

Re: Taming The Switch-Statement

#501
From: bart
Date: Sun, 18 Oct 2026 13:33
159 lines
7408 bytes
On 18/10/2026 12:22, David Brown wrote:
> On 17/10/2026 13:34, bart wrote:
>> On 17/10/2026 04:19, Dan Cross wrote:
>>> In article <11auad0$3no1k$1@dont-email.me>, bart  <bc@freeuk.com> wrote:
>>
>>>> Those are considered more productive.
>>>
>>> ...and you think that's because of the syntax, and not the high
>>> level nature of those languages?
>>
>> It's a combination.
>>
>>> Yes, the syntax is pretty gnarly; Dennis Ritchie even said as
>>> much.  Fixed in Go and Rust, but also, I doubt you've ever in
>>> your life had a variable of type array of array of length 8 of
>>> a pointer to a pointer to a function returning an array of
>>> pointers to char.  Finding the most ridiculous example you can
>>> is not really evidence of anything besides your weird obsession
>>
>> That was the first one I saw online next to a quote from K&R and I 
>> assumed it was from the book. In fact the example from the book is this:
>>
>>    char (*(*x())[])()
>>
>> I've no idea what the means either. The point is not that the examples 
>> are ridiculous, but that they are hard to convert to and from LTR form 
>> which is how we think. With LTR syntax it becomes utterly trivial to 
>> read or write them, no matter how complex.
>>
>> (There's a tool called CDECL that translates types from C syntax to 
>> LTR English or vice versa. It calls the C versions 'gibberish'. This 
>> is a real thing!)
>>
> 
> Putting that example in cdecl gives :
> 
> "declare x as function returning pointer to array of pointer to function 
> returning char"
> 
> To me, that is just as much gibberish as the original C.

That doesn't matter - the problem is not even knowing what it 
represents. (That it is an actual function is a surprise. That you can't 
easily tell is crazy.)

In practice there will be actual types that start to look like 
gibberish, full of *, () and [] that must be in exactly the right place.

Then maybe you want to construct a pointer to such a type or an array of 
it - where will be the new * or [] go? Where will the variable name go 
for that matter?

This should be simple enough to do in a language without needing to 
follow some back-and-forth algorithm, or use an external tool, or need 
to decompose them into multiple levels using 'typedef', or need to 
disambiguate with parentheses.

Typedef decomposition can be useful when types are genuinely complex (or 
parts of them are used/shared elsewhere), but it should not be a crutch 
for an unusable type syntax.

In any case, for me the threshold at which I need help is low. I 
couldn't do these for example:

  * Array of function pointers (say taking no params and returning void)
  * Pointer to array of function pointers
  * Function returning pointer to array (of int)
  * Pointer to function returning pointer to array (int)

My tool tells me the answers are these:

   void (*[])(void)
   void (*(*)[])(void)
   int (*(void))[]
   int (*(*)(void))[]

Still gobbledygook, sorry, and these are hardly that complex or 
unrealistic. (Other than 'pointer to array' being an uncommon C idiom. 
It's only uncommon because other C syntax choices make it ungainly to 
work with.)

Of those four lines, one is an actual function; another is a pointer to 
a function. Plus there is an array, and a pointer to something else. But 
this is not obvious at a glance, because the key part is buried in the 
middle. In an LTR scheme, it would be first.

> No syntax is 
> going to make sense of it - no amount of "ref" or "func" or pre-fix 
> array notation will help.

It will tell you what it is, which is a start. Those four examples I 
gave would look like this:

   []ref proc               # 'proc' is 'func -> void'
   ref []ref proc
   func -> ref []int
   ref func -> ref []int

Using a scheme I once proposed for C, to work side-by-side with the 
current syntax, I believe it would be like this:

   []*func()void
   *[]*func()void p, q;
   func F()*[]int {}
   *func()*[]int

Variable names would go on the right as in the second example. For that 
actual function however, an earlier name looks better and matches other 
languages.

> If you want complex types in a programming language, make them out of 
> simpler, named types that express what you are trying to achieve.  I 
> think any decent typed programming language will have a way to do this - 
> for C, "typedef" is your friend here.
> 
> (And do /not/ reply by bringing up examples you have cherry-picked from 
> code you have found, as though it was my fault they wrote 
> incomprehensible code.)

But that is going to happen. You will come across such types.

> C is not, and has never claimed to be, a beginner-friendly language.

If something is needlessly complex and unintuitive, that will be the 
case for everyone.

For beginners to C, it is just an unnecessary obstacle. I can see many 
giving up on it for that reason.

One way to simplify types is to use 'typeof' (I've no idea whether it is 
still an extension or now standardised). That means being able to write:

    typeof(int*) p, q, r;

instead of: 'int *p, *q, *r' which is too tempting to write as 'int* p, 
q, r'.

This solves another issue where the type of any declared variable is 
split up into up three pieces in three different places:

    int a, b, *c[10];


The type of 'c' comprises 'int', '*' before the name, and '[]' after the 
name. This makes it hard to share too. 'typeof' allows this (or along 
these lines):

    typeof(int*[]) x, y, z;

The type is in one tidy place, and it can be shared. This is how C 
should have worked in the first place, and it wouldn't have needed that 
untidy 'typeof()'.


>  It 
> is designed to be efficient while remaining quite a small language, 

C's type declarations are actually harder to parse than a conventional 
LTR scheme. That means a more complex compiler front-end.
Technical Details
Message-ID: <11b2hr6$15thq$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> <11arjmc$2qid7$1@dont-email.me> <11at5vi$5vu$1@reader2.panix.com> <11auad0$3no1k$1@dont-email.me> <11aupfl$3ul$1@reader2.panix.com> <11avmfb$55rt$1@dont-email.me> <11b2a6d$131h6$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: bart <bc@freeuk.com>
Newsgroups: comp.lang.c
Subject: Re: Taming The Switch-Statement
Date: Sun, 18 Oct 2026 14:33:25 +0100
Organization: A noiseless patient Spider
Lines: 159
Message-ID: <11b2hr6$15thq$1@dont-email.me>
References: <119qf6l$2rmg3$1@dont-email.me> <11arjmc$2qid7$1@dont-email.me>
 <11at5vi$5vu$1@reader2.panix.com> <11auad0$3no1k$1@dont-email.me>
 <11aupfl$3ul$1@reader2.panix.com> <11avmfb$55rt$1@dont-email.me>
 <11b2a6d$131h6$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 18 Oct 2026 13:33:27 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="1242682"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/U6TX2uOcfgu8YOY0NXAXa"; posting-host="c99c9a957370eff0b06f081ccfe4e16c"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:PejzbVL19Az1VxN0TDUGv6/Y/60= sha256:yBtZysfMvBH5fgEDelu7QC74uiMazNRBq1GlYr8aV3w=
	sha1:ohnSB7sitWegKbopPmVhfSoh1Zw= sha256:gi15LQ0fw1Ny0mPzD0myxR/zOdGZ2BiLyEeivayuYO8=
In-Reply-To: <11b2a6d$131h6$1@dont-email.me>
Content-Language: en-GB