2 ms·
> Another option is for the macro to define a separate function type typedef (properly mangled with the line number) for the function type and then use it to de
by naasking 10y ago
> Another option is for the macro to define a separate function type typedef (properly mangled with the line number) for the function type and then use it to define a pointer to it.
Yes, but this requires forward declarations of the function type, which seems unnecessary. I can now just write:
void sort(int* vals, int vcnt, fn(int, int, int) compare);
int* filter(int* vals, int vcnt, fn(int, bool) clause, int* rcnt);
without any forward declarations, and it's still immediately obvious what's going on. This approach makes C semantically a little more like a functional language without sacrificing a single thing people love about C (I hope).