473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Callback function?

Hi all,
Can any one explain me what is callback function....
I have written some code after reading some tutorials from internet...
But I am not sure is it a right way to write a call back function...
I have mentioned my doubts in code comments.
My code is...

void myfun_callback(void(*fp)(char*)) //is this function is a call
back?
{
(*fp)("Pradeep Kumar");
}

void A(char *msg) //function A,called by myfun_callback
{
cout<<"Function A: "<<msg<<endl;
}

void B(char *msg) //function A,called by myfun_callback
{
cout<<"Function B: "<<msg<<endl;
}

int main()
{
void(*fp)(char*); //function pointer
fp=A; //giving address of function A
myfun(fp); //right way to call the callback function?
fp=B; //giving address of function B
myfun(fp); //right way to call the callback function?
return 0;
}

ur help will be appreciated..
Thank u in advance

Regards
Pradeep Kumar Basrani

Jun 27 '07 #1
2 2599
Pradeep wrote:
Can any one explain me what is callback function....
A callback function is a function pointer to which is supplied to (and
stored by) the system (whatever the system is) to be called at some
indetermined time, generally speaking. Sometimes the time at which the
callback is called is a bit clearer defined, but it doesn't mean the
path to the callback is (or can be) determined.
I have written some code after reading some tutorials from internet...
But I am not sure is it a right way to write a call back function...
I have mentioned my doubts in code comments.
My code is...

void myfun_callback(void(*fp)(char*)) //is this function is a call
back?
No. This function is not a callback _unless_ you give it to some
other function to be called.
{
(*fp)("Pradeep Kumar");
}

void A(char *msg) //function A,called by myfun_callback
This function is most likely a callback.
{
cout<<"Function A: "<<msg<<endl;
}

void B(char *msg) //function A,called by myfun_callback
This is another function that is likely a callback.
{
cout<<"Function B: "<<msg<<endl;
}

int main()
{
void(*fp)(char*); //function pointer
fp=A; //giving address of function A
myfun(fp); //right way to call the callback function?
It's a way to call a function that will *in turn* call the
callback you supply to it.
fp=B; //giving address of function B
myfun(fp); //right way to call the callback function?
return 0;
}

ur help will be appreciated..
Thank u in advance
Try to use English here and avoid chatroomisms.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 27 '07 #2
A callback function is a function in your code that is called by
something outside of your control; it could be the operating system,
or it could be a 3rd party library you are using.

This typically means you first give out a pointer to that function to
the external caller.

Other than that, it's a function like any other, but of course, it
should work according to what the external caller expects.

Jun 27 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Marian Aldenhövel | last post by:
Hi, I am using the FMOD audio-library with the pyFMOD python bindings. pyFMOD uses ctypes. It is possible to register callback functions with FMOD that are called at certain points in the...
4
by: ma740988 | last post by:
// file sltest.h #ifndef SLTEST_H #define SLTEST_H class CallbackBase // herb shutters gotW source .. { public: virtual void operator()() const { }; virtual ~CallbackBase() = 0; };
15
by: Felix Kater | last post by:
Hi, in a given library I register callback functions with this function: bool set_callback(int index, int (*callback_function)(long)); I need the callback function to also pass the index...
8
by: kurtcobain1978 | last post by:
-------------------------------------------------------------------------------- I need to do the exactly same thing in VB.NET. Load a unmanaged C DLL dynamically and then call a function in...
6
by: smmk25 | last post by:
Before I state the problem, I just want to let the readers know, I am knew to C++\CLI and interop so please forgive any newbie questions. I have a huge C library which I want to be able to use in...
10
by: SQACPP | last post by:
Hi, I try to figure out how to use Callback procedure in a C++ form project The following code *work* perfectly on a console project #include "Windows.h" BOOL CALLBACK...
0
by: Tim Spens | last post by:
--- On Fri, 6/27/08, Tim Spens <t_spens@yahoo.comwrote: I think I know where the problem is but I'm unsure how to fix it. When I call Register_Handler(...) from python via...
6
by: jmDesktop | last post by:
In a function that takes another function (function pointer) as a argument, or the callback function, which is the one that "calls back"? I'm having a hard time understanding the language. Am I...
5
by: Jef Driesen | last post by:
I have a C DLL that I want to use from a C# project. The C header file contains these declarations: typedef void (*callback_t) (const unsigned char *data, unsigned int size, void *userdata);...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.