Guest User

Untitled

a guest
Oct 17th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. typedef int (*handler_t)(blah_t *, splat_t *, int);
  2.  
  3. // REQ_DO_THIS, REQ_DO_THAT, REQ_DEFENESTRATE are all small integers
  4.  
  5. static const handler_t handlers[] = {
  6. [REQ_DO_THIS] = handle_do_this,
  7. [REQ_DO_THAT] = handle_do_that,
  8. [REQ_DEFENESTRATE] = handle_defenestrate,
  9. ...
  10. };
  11.  
  12. ...
  13.  
  14. if (req < 0 || req >= array_count(handlers) || !handlers[req]) {
  15. return -1;
  16. } else {
  17. return handlers[req](...);
  18. }
Add Comment
Please, Sign In to add comment