4 ms·
Rarely used feature that I quite like is defining function types. typedef bool foo_fn(int, char); This declares a type of a function. foo_fn foo1, foo
by gallier2 6y ago
Rarely used feature that I quite like is defining function types.
typedef bool foo_fn(int, char);
This declares a type of a function.
foo_fn foo1, foo2, foo3, foo4;
This declares 4 functions of the same type. It's equivalent to
bool foo1(int, char);
bool foo2(int, char);
bool foo3(int, char);
bool foo4(int, char);
Unfortunately the type can not be used at function definition but that is not where function are interesting. They are neat for function pointers especially those that require casting.
void function_taking_foo(int, foo_fn *);
function_taking_foo(1, foo1); // no cast necessary as type is identical and even
instead of
function_taking_foo(1, (bool(*)(int,char))foo1);
When you have a lot function pointers it is incredibly more readable than the usual syntax.