/* * Callback table, used for abstracting behaviour. Also known as function * pointer table This is whats caleld a vtable in C++ terms. * * Commonly used as a form of polymorphism */ #include static int global = 0; typedef struct { void (*put)(int); int (*get)(); } Test; void my_put(int a) { global = a; } int my_get() { return global; } void executor(Test *t) { t->put(10); int got = t->get(); printf("Got: %d\n", got); } int main() { Test t = {.get = my_get, .put = my_put}; executor(&t); return 0; }