Step 6 of 6
Challenge: an event bus
A bare function pointer has no memory of its own. To let a callback update your data, C APIs pass a void *ctx ("context" or "user data") alongside it, and hand it back on every call:
typedef void (*Handler)(int event, void *ctx);
That's how GUI toolkits, pthread_create, network libraries and game engines all do callbacks in C.
Your turn: build a tiny event bus that stores up to 8 handler/context pairs.
int bus_on(Bus *b, Handler h, void *ctx): register; returns 0, or -1 when fullvoid bus_emit(Bus *b, int event): calls every handler in registration order with the event and its own ctx