4 ms·
I think the only complicated-looking thing in C is the syntax for declaring function pointer types. If you use typedefs you end up with typedef int (*math_op
by qu4z-2 13y ago
I think the only complicated-looking thing in C is the syntax for declaring function pointer types. If you use typedefs you end up with
typedef int (*math_op)(int, int);
math_op ops[] = {
add,
subtract
};
int a = ops[0](3, 5);
int b = ops[1](9, 2);
... maybe I've just used them too much, but I find them quite simple (except, as mentioned, setting up the initial typedefs which is a bit "odd").
One of my favourite uses of function pointers is for key-mappings, like in: https://github.com/muennich/sxiv/blob/master/config.def.h https://github.com/muennich/sxiv/blob/master/config.def.h