4 ms·
Oh yes! I totally agree with that approach; I find it much clearer to typedef the function type rather than the function pointer type: typedef int (*Callb
by mtklein 4y ago
Oh yes! I totally agree with that approach; I find it much clearer to typedef the function type rather than the function pointer type:
typedef int (*CallbackPtr)(int,int);
void foo(..., CallbackPtr callback);
always reads less clearly to me than
typedef int Callback(int,int);
void foo(..., Callback* callback);
I find this especially useful in C++ where the callback type could conceivably be some other type like std::function. Seeing that * helps me know at a glance it's probably just a plain old function pointer.
Though I think maybe clearest of all is to not use a typedef, provided it doesn't cause other readability problems:
void foo(..., int (*callback)(int,int));
(Not meaning to steal your thunder here... just wanted to write out an example in case anyone else was curious.)