Created
August 31, 2012 04:24
-
-
Save mbohun/3549045 to your computer and use it in GitHub Desktop.
simple jump table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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