4 ms·
Unfortunately I was astounded, horrified, and simultaneously pleased to discover that I was immediately able to decipher the "hard" (huh ?????) example. Althou
by Arch-TK 2y ago
Unfortunately I was astounded, horrified, and simultaneously pleased to discover that I was immediately able to decipher the "hard" (huh ?????) example.
Although if I was writing this myself, I would split it up like so:
typedef char *StringArray[];
typedef StringArray *Func();
Func **foo[][8];
Which is equivalent and much easier to read. (Although still not trivial. I have no idea what purpose this type really serves. The type names are placeholders as a result.)
C type declarations become particularly tricky specifically when people try to directly declare (or typedef) pointers to functions/arrays without an intermediate typedef for the function/array type.
So if you make it a rule to typedef array types before creating pointers to them (although this usually makes for some rather unreadable code so maybe try avoiding it in general) and to typedef function types before creating pointers to them, you will usually have much more readable code.
As a bonus, you can then use the function typedef to provide an early type-check for a callback function (even if it's a callback your code doesn't directly use). E.g.:
typedef int Func(int a);
Func foo;
int foo(int a)
{
return a * 2;
}
Or, you know, switch to a higher level language.
- dvhh 2y agoWas thinking the same, but there is always this "clever" dev who insist on putting everything in one line