As a generalization I completely disagree. But for function pointers specifically, yes, they are easily the worst part of the C syntax.
>void(signal(int, void ()(int)))(int);
That's just declaring signal as function (int, pointer to function (int) returning void) returning pointer to function (int) returning void, DUH. Thank you cdecl.org
But notice how absolutely ugly it is that the final return type comes first, that is due to the C function signatures.
Seems like a good thing to be honest.
But actually I'd suggest the opposite of disallowing "long long" and making it like signed/unsiged as purely a modifier.
Long long is not even a 64 bit integer type, it’s a int_least64_t. Could be 128 or 256 bits for all you know.
var signal*: proc (a1: cint; a2: proc (a1: cint)): proc (a1: cint)
That reads to me as:Variable signal is a pointer to a function that that takes two arguments (an int, and a function that takes an int), and returns a function that takes one argument (an int).
Of course, I'm assuming my interpretation is correct... perhaps it's not ;)
Note that Nim uses "*" as a public symbol sigil not a pointer. Its a bit odd at first coming from C but is nice and consistent.
var signal*: (cint,(cint)->void) -> (cint)->voidThis is trivial to parse if you use spiral rule, humans or machine.
Not really. Just create a bit mask.
https://github.com/dlang/dmd/blob/master/compiler/src/dmd/cp...
Looks like there's only about ~388 lines of logic to the bitmask? haha your definition of difficult might not match mine. ;)
void(*signal(int, void (*)(int)))(int)
The result of the expression is void.Parentheses go first in order of operations, so we evaluate this first:
(*signal(int, void (*)(int)))
Function call binds before dereference, so this goes first: signal(int, void (*)(int))
"signal" becomes the actual declared name. At the bottom, we have a function that takes two parameters, an int, and a function pointer that takes an int and returns void. Now we work outwards.This function returns a pointer, that when dereferenced, can be called with an int, and returns void when doing so.
In layman's terms, we have a function "signal" that takes an int and a function pointer and returns a function pointer, and both function pointers are to a function that takes an int and returns void.
Is it easy? If you can read C expressions, it can be easy. But it is definitely tedious, and does not come out quickly--it violates the principle that you have <type> <variable name>; it is not what I would consider readable or good design. And it would be easier if types were consistently read in one direction (like Rust types).
I recently submitted a PR for the `c2nim` import tool to handle double function pointers. I didn't actually understand the C code until I got the transpiler working despite cdecl.org:
in Nim becomes: Well I'm 99.5% certain at least. Even now I'm uncertain of the C syntax. And I've not been bold enough to test 3rd order C function pointers. I figure that's probably C code you don't wanna touch if possible.https://github.com/nim-lang/c2nim/blob/11f2c5363dfe7e8c7c8ce...
The other annoying one is that "signed" and "unsigned" are basically adjectives, but "long" can be both a type and a modifier. So it's difficult to parse unless you're the target C compiler. Technically you can, but you have to use backtracking.