Help on callback function

A

Ajay

Hi all,
Can you please give a good example of callback function.I
tried on google Search but could not found the good one.I am working in
embedded system so giving example in the same context would be
helpful.thanks in advance.Ajay
 
I

Ian Collins

Ajay said:
Hi all,
Can you please give a good example of callback function.I
tried on google Search but could not found the good one.I am working in
embedded system so giving example in the same context would be
helpful.thanks in advance.Ajay
Your embedded device might have a driver for an input device, that
driver might be wired to call a function provided by a higher layer when
it receives some data.

Something like:

void (*dataCallback)(const char*);

void registerDataCallback( void (*fn)(const char*) )
{
dataCallback = fn;
}

Then somewhere in the driver..

void passOnData(const char* data)
{
if( dataCallback )
{
dataCallback( data );
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,968
Members
47,517
Latest member
TashaLzw39

Latest Threads

Top