When writing C (and sometimes C++) code, make sure that whenever you accept a function pointer as a callback, that it also accepts a void *
context variable, which would be passed to the function as well. These variables are sometimes called “batons” because they are passed around. Without this convention, it will be harder to instantiate routines based on this interface, and multi-threading will be harder without the use of thread-local-storage.
So don't do that:
# Bad code void my_sort(my_type * const array, const size_t count, int (*compare)(my_type *, my_type *));
And instead do that:
void my_sort(my_type * const array, const size_t count, int (*compare)(my_type *, my_type *, void *), void * const context);