mbohun
8/31/2012 - 4:24 AM

simple jump table

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;
}