Article View: comp.lang.c
Article #614Re: Taming The Switch-Statement
From: bart
Date: Tue, 20 Oct 2026 20:07
Date: Tue, 20 Oct 2026 20:07
168 lines
7239 bytes
7239 bytes
On 20/10/2026 16:02, David Brown wrote:
> On 20/10/2026 16:11, bart wrote:
>
>> The other was C. There, several choices were made:
>>
>> * To start with that Fortran style except that [] are used
>>
>> * To decree that that 'A[20]' syntax is supposed to match indexing of
>> A as it might appear in an expression
>>
>> * To introduce "*" as a prefix dereference operator in expressions ...
>>
>> * ... which then means that a prefix "*" appears in the declaration too
>>
>> * A further complication was to allow function pointers within that a
>> declaration list
>
> I don't see a problem with that. If you need to declare a function
> pointer, you need to declare it in a declaration list.
>
> To me, the big disadvantage of C's declaration syntax is that it lets
> you declare things of different (but related) types in the same
> declaration.
Yes, but that doesn't bite so much because it is uncommon.
> or, more common and therefore worse :
>
> int * a, b;
(See below.)
>> * Yet one more which came later was to add 'const', where placement now
>> gets confusing
>
> Some people do find it hard to understand the difference between :
>
> const int * p;
> int * const q;
> const int * const r;
>
> I note that this is despite the clear left-to-right nature of "const" here.
I was going to say it was right-to-left, but it can be considered both
and thus not clear:
const int const * const p;
1 2 3
const 1 applies to the basetype to its right.
const 2 applies to the basetype to its left.
(Both also can be in the middle with compound types like 'long long'!)
const 3 is tricky: I think it applies to the * to its left, since it
says that the pointer value itself is const. But 'p' has type 'pointer
to', so it could apply to that directly.
What about this however:
int * const * p;
1 2 3
I think here, const 2 applies to * 1, which is to it's left, and can't
apply to 'p' as that is the other side of the * 3.
Fair to say that is a complete mess, and it is error prone.
With a LTR syntax that a postfix deref would achieve, 'const' would
always be written immediately to the left of any * modifiers. (It is
meaningless for arrays and functions.)
It is never applied directly to a variable name.
For base types, it can be applied on the left, but C would still allow
it on the right or in the middle, or all three with duplicates.
That means there would be an ambiguity here where there is no identifier
between 'int' and 'const':
(const int const *)
For such reasons I would restrict base type const to be only on the left.)
> Complicated types are a minority.
I've showed even simple types or trying to use 'const' get becomes
confusing.
>> So, PARENTHESES HAVE BEEN ELIMINATED for purpose of disambiguating
>> array/pointer and pointer/array, both within expressions and within
>> type-declarations.
>
> Agreed.
>
> But does that make a significant difference? I don't think so.
It would make a HUGE difference:
(1) It helps to fix that confusion above
(2) You don't need parentheses so no need to remember if you want
(*A)[] or *A[]. Those will disappear from expressions too; less
clutter all round.
(3) It simplifies indexing of pointer-to-array from (*A)[i] to A*[i], so
that actual array pointers, which are more type-safe, could start to
appear more in C rather than the current T* idiom
(4) For pointers to structs, these are the patterns:
prefix * With -> With postfix *
(*P).m P->m P*.m
(**P).m (*P)->m P**.m
(***P).m (**P)->m P***.m
Which column looks the tidiest?
(5) With prefix *, a pointer type looks like 'T*'; notice the * is on
the right, not left! With postfix *, it would all be consistent. You
also wouldn't have 'T*A'; that would be an error (T* only happens
when there is no name)
(6) Your 'int * a, b' example would become:
int a *, b;
Much easier, even with that space, to see that '*' does not belong to
the base type but is a modifier for that variable.
It doesn't fix everything, so you'd still have this:
int p* = &a;
p* = a;
To fix this requires that all modifiers apply to the base type. But this
would be a massive change. The above is merely what happens when *
becomes postfix.
>> A mistake that could so easily have been avoid by choosing a different
>> precedence as shown above. Did none of the thousand people working at
>> Bell Labs (according to a comment in DC's follow-ip) spot this and say
>> anything?
>
> I suspect the folks at Bell Labs were too busy writing real code to be
> bothered by how confused you would be with artificially complex types.
So you agree the process was very different compared to that which lead
to Ada for example? Just a couple of guys left to do their own thing.
(Maybe they were respected enough that no one dared to offer any
constructive criticism, or if they did then it was dismissed. As happens
here.)
>>
>> (ACTUALLY IT IS NOT TOO LATE. A secondary postfix deref op could have
>> been added. This could have been done 50 years ago, with the original
>> eventually deprecated.
>
> It /is/ too late - far, far too late. It would be a terrible idea to
> add a new postfix dereference operator to give two different operators
> with no benefit other than very occasionally reducing the need for
> parentheses.
But a special operator P->m to do the same job as (*P).m was fine! The
new op would eliminate the need for ->.
Technical Details
Message-ID:
<11b8hln$3be6n$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> <11avmfb$55rt$1@dont-email.me> <11b0cvs$skc$1@reader2.panix.com> <11b0mfv$j5ll$1@dont-email.me> <11b3r71$6me$1@reader2.panix.com> <11b500f$216c4$1@dont-email.me> <11b6ekh$d2qm$1@paganini.bofh.team> <11b7sqn$32pr5$1@dont-email.me> <11b7vqd$2m8c9$6@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: Tue, 20 Oct 2026 21:07:20 +0100 Organization: A noiseless patient Spider Lines: 168 Message-ID: <11b8hln$3be6n$1@dont-email.me> References: <119qf6l$2rmg3$1@dont-email.me> <11avmfb$55rt$1@dont-email.me> <11b0cvs$skc$1@reader2.panix.com> <11b0mfv$j5ll$1@dont-email.me> <11b3r71$6me$1@reader2.panix.com> <11b500f$216c4$1@dont-email.me> <11b6ekh$d2qm$1@paganini.bofh.team> <11b7sqn$32pr5$1@dont-email.me> <11b7vqd$2m8c9$6@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Tue, 20 Oct 2026 20:07:20 +0000 (UTC) Injection-Info: dont-email.me; logging-data="3520727"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Zr3o7jxjWGNP+ryN19CkK"; posting-host="7c142682e3246f1a229ef2ca48617714" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:A4njUPXForsaMON+7oo9WciYwZk= sha256:/MI3EsKguay/XtBWVGjZPm46DNQxy0sYjZfe0ylSiF0= sha1:i1wWB9wgAYgl/O7jD/psS3Tp2+8= sha256:he5PCvPNX1cMzcp1B2l447sMV7a/ZPzNGOBxL35xIi0= In-Reply-To: <11b7vqd$2m8c9$6@dont-email.me> Content-Language: en-GB