I am not sure about this function pointer type declaration syntax, but it works. The syntax is just like declaring a regular old function.
typedef struct Element GetChildCallback(void *userdata, usize parent, usize child_no);
I couldn't find any information on how standard-compliant it is or what drawbacks it could possibly have.
I thought this only worked for typedefs, so I took a step further and found out this also works for regular function parameters:
extern inline void dmpstrn(const char *t, usize n, int printer(const char *fmt, ...));
inline void dmpstrn(const char *t, usize n, int printer(const char *fmt, ...)) {
usize len = strlen(t) > n ? n : strlen(t);
printer("\"");
for (usize i = 0; i < len; i += 1) {
if (t[i] == '\n')
printer("\\n");
else
printer("%c", t[i]);
}
printer("\"\n");
}
// ...
int main() {
dmpstrn("Hello\nworld", UINT64_MAX, printf);
}
This however doesn't work for variables
int printer(const char *fmt, ...) = printf; // Invalid
It's as if the it isn't the function pointer but the actual function, but what does it mean?