What do you mean by registering a callback function in C?

Can someone tell me what we definitely mean by registering a callback function in C with some examples? I searched a lot on the net, but I could not get satisfactory answers. I even looked for a stack overflow, but could not get a perfect idea of ​​this.

What are Notify callbacks and asynchronous callbacks?

+6
source share
1 answer

Registering a callback function simply means that you are organizing an external object to call your function.

This can happen later, or it can happen right away. A direct example is qsort . It is declared as follows:

 void qsort(void *base, size_t nel, size_t width, int (*compar)(const void *, const void *)); 

To use it, you must pass a pointer to a function that compares elements - a callback.

This was a simple example, but as a rule, “registering a callback” means passing a pointer to a function to someone who will call it for you in the future.

+11
source

Source: https://habr.com/ru/post/904238/


All Articles