Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef int (*handler_t)(blah_t *, splat_t *, int);
- // REQ_DO_THIS, REQ_DO_THAT, REQ_DEFENESTRATE are all small integers
- static const handler_t handlers[] = {
- [REQ_DO_THIS] = handle_do_this,
- [REQ_DO_THAT] = handle_do_that,
- [REQ_DEFENESTRATE] = handle_defenestrate,
- ...
- };
- ...
- if (req < 0 || req >= array_count(handlers) || !handlers[req]) {
- return -1;
- } else {
- return handlers[req](...);
- }
Add Comment
Please, Sign In to add comment