🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #549

Re: Taming The Switch-Statement

#549
From: David Brown
Date: Mon, 19 Oct 2026 13:46
62 lines
4819 bytes
On 19/10/2026 15:16, Janis Papanagnou wrote:
> On 2026-10-18 21:09, David Brown wrote:
>> On 18/10/2026 18:09, bart wrote:
>>> [...]
> [ declaration syntax ]
> 
> (I just want to comment on a [not unimportant] detail...)
> 
>>
>> You need to give things in the right order, or use parentheses, to get 
>> the right "type expression".  It's just like any other kind of 
>> expression.
>>
>> The intention of the declaration syntax in C is that the declaration 
>> order follows usage.  [...]
> 
> I think the first part is downplaying that languages typically indeed
> make a distinction between parenthesized expressions and declarations.
> Quite some other languages [not from the C-heritage] that I used all
> did not need to introduce "expression"-grouping for _declarations_ in
> the first place given their more consistent ways to declare entities.
> 
> The second part is, as I had understood C's history, the idea behind
> how it got defined; needless to say that I think that was a bad idea.
> But that's what we've got! If they had dropped that requirement/idea
> the declaration syntax could have become "better" (more consistent,
> less cryptic, less convoluted, clearer). Now, after half a century,
> we just have to live with that, and folks who have "problems" with it
> should better not touch this language (or maybe not doing programming
> at all). The somewhat tragic aspect is that the "declaration follows
> use" idea was (IIRC) intended to _simplify_ the understanding of its
> concepts and use of the language; the consequences were seemingly not
> valued correctly.
> 
There are a number of things that I don't particularly like about C's 
declaration syntax, or where I think it would have been better if it 
were different.  But the "inside-to-outside" ordering is not one of 
them.  That is not because I think it is better or clearer than 
left-to-right ordering, but because when I compare to, say, Pascal, it's 
not a big issue for me.  Far bigger are :

1. People put too much into a single type declaration, rather than 
building types out of logical parts with a purpose and a name.  They 
don't do it as much as Bart likes to pretend, but some people do it too 
much for my liking.  The language doesn't force you to do that - it's 
programmer style.  IMHO there is never a reason for a "pointer to an 
array of function pointers taking int and returning void" - no matter 
what syntax is used.  Give a name to the function pointer type that 
reflects the usage (/not/ a name that reflects the definition), and 
build up from there.

2. Being able to declare variables and functions with different types in 
the same declaration.  Very occasionally, I find it convenient to 
declare more than one variable at once - "int a, b, c;".  It is rare in 
my code - generally it is one variable with an initialiser (and perhaps 
a comment) at a time.  But it is - IMHO - a bad thing that you can write 
"int a, xs[20], *p, (*f)(void);" in one declaration.

Both of these are overcome by simply not writing code that way. 
Obviously that is easy to achieve in my own code, but other people may 
use a different style.
Technical Details
Message-ID: <11b56uo$1q18k$5@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> <11b2l06$16mof$1@dont-email.me> <11b2qv0$19h68$1@dont-email.me> <11b35gt$1cn63$2@dont-email.me> <11b557o$1kr9u$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: Mon, 19 Oct 2026 15:46:00 +0200
Organization: A noiseless patient Spider
Lines: 62
Message-ID: <11b56uo$1q18k$5@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>
 <11b2l06$16mof$1@dont-email.me> <11b2qv0$19h68$1@dont-email.me>
 <11b35gt$1cn63$2@dont-email.me> <11b557o$1kr9u$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 19 Oct 2026 13:46:01 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="1901844"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19c1hJpIe7kyPMkpa/7tc9zj4mef9uY8XA="; posting-host="f8e69aeaa618e660247a66e432a03539"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:JiphXQksvubL0X4i+O0LE/tdMuk= sha256:uoA2v7yqGGUORf6zUA9D0yMF4cknd8rJ2j9KzCwSuT8=
	sha1:Ig8W1OxuZJRg0GbrLGGmVazwVXw= sha256:ioYLOSW4fyC2ph8IplXbKnB3/XcM/ef8cZ03EEi67t8=
Content-Language: en-GB, nb-NO
In-Reply-To: <11b557o$1kr9u$1@dont-email.me>