I have started to review callbacks. I found this link on SO:
https://stackoverflow.com/questions/142789/what-is-a-callback-in-c-and-how-are-they-implemented It has a good example of callback which is very similar to what we use at work. However, I have tried to get it to work, but I have many errors.
/* Is the actual function pointer? */
typedef void (*event_cb_t)(const struct event *evt, void *user_data);
int event_cb_register(event_ct_t cb, void *user_data);
static void my_event_cb(const struct event *evt, void *data)
/* do some stuff */
struct event_cb *callback;
I know that callbacks use function pointers to store an address of a function. But there are a few things that I find I don't understand:
* What is meant by "registering the callback" and "event dispatcher"?
以上就是Function pointers and callbacks in C的详细内容，更多请关注web前端其它相关文章！