2 ms·
For those less familiar with C I'd like to point out that a common solution to the "function pointer hell" in C is to alias the types with typedef, although one
by simias 12y ago
For those less familiar with C I'd like to point out that a common solution to the "function pointer hell" in C is to alias the types with typedef, although one might argue it's more a workaround than a real solution.
So the last example of function pointer taking a function pointer parameter and returning a function pointer could look something like:
typedef int (*return_fp_t)(int, int);
typedef int (*param_fp_t) (int, int);
return_fp_t do_stuff(param_fp_t a, int b) {
/* ... */
}
It requires coming up with new type names but it remains pretty readable in my opinion. Also if the prototype of one of the function changes (which is pretty common in my experience) it's easier to modify it since it's only declared once.