Article View: comp.lang.c
Article #527Re: Taming The Switch-Statement
From: bart
Date: Sun, 18 Oct 2026 22:20
Date: Sun, 18 Oct 2026 22:20
199 lines
7648 bytes
7648 bytes
On 18/10/2026 20:09, David Brown wrote:
> On 18/10/2026 18:09, bart wrote:
>> Isn't that the problem? C makes it tricky. Here are two very
>> straightforward declarations from my projects:
>>
>> ref []ichar stringtable # ichar is ref char
>> [N]ref proc(T) handlertable
>
> Are you suggesting that in your language, "stringtable" could also be
> declared as :
>
> ref ichar [stringtable]
> or
> ][ stringtable ichar ref
> ?
(Warning: longer post than I'd intended.)
I think you're clutching at straws.
[] or [N] means 'array of'
ref means 'pointer to'
proc means 'function returning void'
Then there is an existing standard or user type T.
You use these building blocks to construct types of any complexity. They
are simply chained together, from left to right, ending with T at the right.
If this is part of a variable declaration, then names follow on the
right (but syntaxes vary here).
So you know that ][ makes no sense. Neither does [stringtable] unless
'stringtable' is a valid array-bound expression.
Example, I want a 'pointer to an array of pointer to int':
pointer to array of pointer to int English and CDECL
ref [] ref int My syntax
So 'ref [] ref int'. Now I want to declare 3 such variables of the same
type; no problem:
ref [] ref int x, y, z
Now let's try the same exercise with C:
'pointer to' is *
'array of' is []
But how TF do they go together? Where do I start? It seems I may have to
start from the other end:
int
Now I add the pointer:
int *
I know this far! Now I need to apply [] somewhere, and then another *,
but this can't be it:
int *[]*
OK, here's one I prepared earlier (I didn't need CDECL at all...):
int *(*)[]
Now how about my three variables? Well, here's where the first goes, and
CDECL agrees with me:
int *(*x)[]
But what about y and z? It seems that, in C, the parts of typespec other
than the final T can't be shared. So it has to be this:
int *(*x)[], *(*y)[], *(z)[];
OK, obviously I lied; I had to use CDECL even for a fairly simple type,
because I find C type syntax utterly impossible.
> I suspect that your language also requires the syntactical elements to
> be in the right place.
The difference is that that is literally as simple as writing ABC. This
is the example above:
pointer to array of pointer to int x
ref [] ref int x
A B C D E
The C version is:
int *(* x)[]
D C A E B
Well it's either C A or A C; I don't know, and I don't care as
thankfully I'm not going to deal with this godforsaken language any more.
> I assume that :
>
> [N] ref proc(T) handlertable
>
> and
>
> ref [N] proc(T) handlertable
>
> are different?
Start on the left. One is an array, the other a pointer (to an array of
functions so it's not valid).
> 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.
So, what do you think the purpose of CDECL is? Since to you, NOTHING
about C type syntax ever appears to be a problem.
Try explaining to me in English what either of those two types are.
You're going to describe them in left-to-right order just like CDECL.
This is also how I would think of them. Then my syntax merely
transcribes that exactly: I can write it as fast as I can type and I
will be 100% sure it corresponds to the type I want.
Try reading a C type spec out loud in the order it is in source code,
complete with parentheses. It just does not work!
> The intention of the declaration syntax in C is that the declaration
> order follows usage.
Which doesn't work either. If I declare P to be a pointer to int, then
it will likely be used like this in an expression:
P
I might also write &P, or *P, or P[i], or *(P + i). With a more complex
type I might also partially dereference or index it.
Now tell me that the declaration of a struct also follows its usage!
> There's a lot of good things to say about
> left-to-right ordering, since that is the order for reading (in English,
> anyway). But it also means the declaration order and usage order are
> different unless your array subscript, pointer dereference and call
> operators are also all left-to-right.
Is that important? People don't seem to have a problem writing
expressions in any language, other than quibbles about post- and pre-fix
operators.
But why is it necessary for the shape of a declaration to have anything
to do with what happens in an expression? I've showed that that can vary
anyway, and with some things (such as structs) it is meaningless.
It simply does not work in C, and just leads to confusion:
int a;
int
*p = &a;
*p = a;
The LHSs of those last two lines are the same, but the RHSs must be
different. One of them is being dereferenced, and the other isn't, even
those both /look/ as though they dereference p.
NO DEREFERENCING is done in the declaration, but it uses dereference
syntax in something that looks exactly like an assignment.
Just admit that the whole concept was a failure. The creators have
already done so.
> My point is not that C's syntax
> is wonderful (I disagree with Kenny here),
He was probably being sarcastic.
> but that it works fine in
> practice,
It works in practice with a lot of trouble, but it is not fine.
> you don't have to write incomprehensible declarations
My threshold is lower than yours. Just mix one * and one [], and I'm
already lost.
That you need to disambiguate using () to distingish *[] from (*)[] is
the wrong approach. That changes between pointer/array and
array/pointer, but mysteriously the * and [] stay in the same order?
Technical Details
Message-ID:
<11b3gng$1i4mh$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> <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>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 23:20:31 +0100 Organization: A noiseless patient Spider Lines: 199 Message-ID: <11b3gng$1i4mh$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> <11b2l06$16mof$1@dont-email.me> <11b2qv0$19h68$1@dont-email.me> <11b35gt$1cn63$2@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 22:20:33 +0000 (UTC) Injection-Info: dont-email.me; logging-data="1643217"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+gMLqLOwIXisBmJ3QSehKO"; posting-host="c99c9a957370eff0b06f081ccfe4e16c" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:4geyHqcGK4Ay1UjnC+ElLT3oObE= sha256:NXn9zOUplVJZSZyrY7uKU/HdKTQyDkk+vhLeGvLSCIc= sha1:6CmRUEhFviJK/EPLmqMyjMcDdyo= sha256:QtwB0oZ54oDfMPf1CFmREluhJd09ThVCumI1iKf9m2Y= Content-Language: en-GB In-Reply-To: <11b35gt$1cn63$2@dont-email.me>