Skip to content

Instantly share code, notes, and snippets.

@mbohun
Created August 31, 2012 04:24
Show Gist options
  • Save mbohun/3549045 to your computer and use it in GitHub Desktop.
Save mbohun/3549045 to your computer and use it in GitHub Desktop.
simple jump table
#include <stdio.h>
enum {
FOO,
BAR,
LAST
};
static void foo() { printf("foo\n"); }
static void bar() { printf("bar\n"); }
static void (*a[LAST])() = {
[FOO] = foo,
[BAR] = bar
};
int main(int argc, char* argv[]) {
a[FOO]();
a[BAR]();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment