🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #504

Re: Taming The Switch-Statement

#504
From: David Brown
Date: Sun, 18 Oct 2026 14:27
97 lines
5619 bytes
On 18/10/2026 15:33, bart wrote:
> 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 is, shall we say, a strange attitude.  Gibberish (since that seems 
to be the preferred term here) is gibberish, no matter the language or 
representation, and is equally meaningless and useless.

> (That it is an actual function is a surprise. That you can't 
> easily tell is crazy.)

You can tell it very easy from the C - the final bit is parentheses.

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

Not in my code, or the code I work with - types are clear to me.  Again, 
experiences can vary.  (Of course the syntactical elements must be in 
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?

Use a typedef.  Or since C23, use type inference - that can save naming 
and identifying types when things get complex, and makes it easier to 
write more general code.  Like all language features, there are times 
when it is appropriate, and times when it is inappropriate.  But if 
you've got something "foo" (an object, function, type, etc.) and you 
want an array of 26 of that type, type inference makes that simple - the 
type of "foo" is "typeof(foo)" :

	typeof(foo) xs[26];

If you want a pointer to the object "foo", "auto * p = &foo;".  This is, 
IMHO, a nice addition in C23, but it would have been nicer to have had 
it earlier.  (It's been a gcc extension for a long time.)

> 
> 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.

You just /have/ to whine, don't you?  Whenever you complain - usually 
due to ignorance or prejudice - that something is difficult or 
complicated in C, and someone tells you how it can be handled simply and 
clearly, you are unable to simply say "Okay, thanks - that's good to 
know" or "Sorry, I was wrong, I thought it was hard".  You can't help 
but call things workarounds, or complicated, or get your knickers in a 
twist about having to use a language feature that for some reason you hate.

Technical Details
Message-ID: <11b2l06$16mof$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> <11b2hr6$15thq$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: David Brown <david.brown@hesbynett.no>
Newsgroups: comp.lang.c
Subject: Re: Taming The Switch-Statement
Date: Sun, 18 Oct 2026 16:27:18 +0200
Organization: A noiseless patient Spider
Lines: 97
Message-ID: <11b2l06$16mof$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> <11b2hr6$15thq$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 14:27:19 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="1268495"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX193HO9eBjG2Zk2kLvsu9omwGMKwT3gnSO8="; posting-host="a272f2752d0a4376a695806f42b83d2a"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:tMqq6nLIwajiGnS9BOGBDOxj/Q0= sha256:pSokY+iqqo8kvul+E5Voy/lJQ6LS9lyGm71gwq6r6Sw=
	sha1:D+IVRhchXNv6LPlWi6IDw+jnb/Q= sha256:t9gCVcWKdfhcERLCM4nFJOWi8RqVhiMkSJKE5kBVBFE=
In-Reply-To: <11b2hr6$15thq$1@dont-email.me>
Content-Language: en-GB