Is there any way to create callbacks and signals in C?
I can use function pointer of course, but I want create a signal that can hold multiple functions i.e can bind to multiple events. Something like boost.signals but in C . Is there any way?
There are many gui libraries in C that use callbacks, how do they achieve it?
A simple solution is to keep a list of functions to call, and in the signal handler just iterate over that list calling every function.
Something like this:
Note: There is no error handling, and no freeing of allocated memory. That’s left as an exercise for the reader. 🙂