Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c

callback

Can anyone please tell me,

  • what exactly is meant by registering a callback function in C (with some examples)?
  • what are Notify callbacks ?
  • what are Asynchronous call backs?
like image 908
Maddy Avatar asked Dec 21 '11 13:12

Maddy


People also ask

How do I register a callback function?

To register a callback function for the service object to invoke, use the IUPnPService::AddCallback method. This method can be used to register more than one callback. Developers should not cancel an asynchronous operation inside an asynchronous callback.

What is callback function in C with example?

We can define it in other words like this: If the reference of a function is passed to another function argument for calling, then it is called the callback function. In C we have to use a function pointer to call the callback function. The following code is showing how the callback function is doing its task.

Why do we need callback functions in C?

Callback functions are an essential and often critical concept that developers need to create drivers or custom libraries. A callback function is a reference to executable code that is passed as an argument to other code that allows a lower-level software layer to call a function defined in a higher-level layer(10).

What is callback function and how it works?

A callback is a function passed as an argument to another function. This technique allows a function to call another function. A callback function can run after another function has finished.


1 Answers

Registering a callback function simply means that you are arranging for an external entity to call your function.

It might happen at a later time, or it might happen straight away. A straightforward example is qsort. It is declared like this:

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

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

That was a simple example but generally "registering a callback" means passing a function pointer to someone who will call it for you in the future.

like image 64
cnicutar Avatar answered Oct 05 '22 11:10

cnicutar