Function pointers and callbacks in C

I have started to review callbacks. I found this link on SO: 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. #include /* Is the actual function pointer? */ typedef void (*event_cb_t)(const struct event *evt, void *user_data); struct event_cb { event_cb_t cb; void *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 */ } int main(void) { event_cb_register(my_event_cb, &my_custom_data); struct event_cb *callback; callback->cb(event, callback->data); return 0; } 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前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » CSS3 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准