Sujet : Re: do { quit; } else { }
De : bc (at) *nospam* freeuk.com (bart)
Groupes : comp.lang.cDate : 12. Apr 2025, 00:13:30
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vtc7mp$2q5hr$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
User-Agent : Mozilla Thunderbird
On 11/04/2025 22:36, Keith Thompson wrote:
bart <bc@freeuk.com> writes:
[...]
Rubbish. Everyone finds C declaration syntax a nightmare.
Rubbish. I find C declaration syntax annoying, not a "nightmare".
Annoying would be having to get letter case or punctuation just right.
But C typepecs can go far beyond it. I can just about do arrays of pointers, or pointers to arrays. Anything more complicated is pretty much trial and error.
In an example in my post which I then deleted (DB will just ignore examples), I wanted to create an array of 10 pointers to functions that take an int and return an int.
I started with something like this that I recalled from memory (otherwise it would be even more wrong):
int (*A)[10](int);
but CDECL said it was something different. I tried one or two more combinations before I gave up and asked CDECL to tell me the type from the English.
C type syntax is just not fit for purpose. This is not how a language is meant to work, and this is not supposed to be the hard part of a language! Syntax should be the easy bit.
This is that English spec (with the significant bits numbered):
array 10 pointer to func take int return int
1 2 3 4 5 6
Here is what CDECL came up with:
int (*A[10])(int);
6 3 1 2 4 5 (Not sure which bit is the '4')
The numbers below show the correspondence with the English. You can see it's all over the place. This is how I'd write it in another actual language syntax:
[10]ref func(int)int A
1 2 3 4 5 6
Notice that that numbering here exactly corresponds to the English. THIS is how easy it should be. I could write this as fast as I can type.
Further, the variable name is well out of it. In my syntax, any names go on the right; names on the left is also popular. But no language other than C and C++ has names IN THE MIDDLE.
So, yeah, a 'nightmare' is more apt than 'annoying'.