|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
What are callback function ?
how are they implemented and where they are useful ? what are the advantages of function pointer ? |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
prashant.khade1623@gmail.com wrote:
> What are callback function ? > > how are they implemented and where they are useful ? > > what are the advantages of function pointer ? Have you looked for the answers? -- Ian Collins. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On Apr 11, 1:41pm, Ian Collins <ian-n...@hotmail.com> wrote:
> prashant.khade1...@gmail.com wrote: > > What are callback function ? > > > how are they implemented and where they are useful ? > > > what are the advantages of function pointer ? > > Have you looked for the answers? > > -- > Ian Collins. I have googled.. but I couldnt find something which I can understand |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
prashant.khade1623@gmail.com said:
> What are callback function ? Functions that you tell other functions about. > how are they implemented The function is implemented in the usual way - i.e. it's a function. The callback bit is done via a pointer to the function - you pass such a function pointer to the function that you want to call you back. > and where they are useful ? Callbacks are useful when you are providing a generalised algorithm, with specific functionality details being provided by any of potentially many callers, all with different requirements. Scary stuff, but callbacks make it easy. See, for example, qsort, bsearch, and signal. Or consider a function that accepts a callback pointer and "walks" the members of a container (e.g. a tree or a list), calling the callback function once per member, and passing the member data to the function. Or, of course, consider Win32 API programming, where each window procedure is a callback. > what are the advantages of function pointer ? They let you do callbacks. (There are other uses too, but that'll do for now.) -- Richard Heathfield <http://www.cpax.org.uk> Email: -http://www. +rjh@ Google users: <http://www.cpax.org.uk/prg/writings/googly.php> "Usenet is a strange place" - dmr 29 July 1999 |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
<prashant.khade1623@gmail.com> wrote in message
news:faf90c22-c153-4367-849b-d1610dc6606f@w4g2000prd.googlegroups.com... On Apr 11, 1:41 pm, Ian Collins <ian-n...@hotmail.com> wrote: > > prashant.khade1...@gmail.com wrote: > > > What are callback function ? > > > > > how are they implemented and where they are useful ? > > > > > what are the advantages of function pointer ? > > > > Have you looked for the answers? > > > > -- > > Ian Collins. > I have googled.. but I couldnt find something which I can understand Inform your professor immediately. Give him an example that you don't understand... See what his reaction is... Who knows, she/he may try to you understand... |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
Richard Heathfield wrote:
> prashant.khade1623@gmail.com said: > >> What are callback function ? > > Functions that you tell other functions about. > Doing homework now are we? -- Ian Collins. |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
Ian Collins said:
> Richard Heathfield wrote: >> prashant.khade1623@gmail.com said: >> >>> What are callback function ? >> >> Functions that you tell other functions about. >> > Doing homework now are we? Hmmm? Oh, er, maybe. Good point. I'M AWAKE! No, actually I might not bezzzzzzzzzzzzzzzzzzzz -- Richard Heathfield <http://www.cpax.org.uk> Email: -http://www. +rjh@ Google users: <http://www.cpax.org.uk/prg/writings/googly.php> "Usenet is a strange place" - dmr 29 July 1999 |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
On 11 Apr 2008 at 8:25, prashant.khade1623@gmail.com wrote:
> What are callback function ? > > how are they implemented and where they are useful ? As well as the traditional uses people have already described, callbacks really come into their own when you're doing GUI programming. Typically, the main thread will just run in a loop, waiting for events to occur - for example, for the user to move his mouse in your window, or click one of your buttons. The GUI framework will provide a mechanism for you to pass it function pointers, which it will then associate with certain events. When an event occurs, the event loop will invoke any callback functions you've provided for that event. Often, the callback function will have parameters, and the event dispatcher will provide you with extra information about the event (perhaps the exact x,y coordinates of the mouse, for example) through the arguments it calls your callback function with. As a simple example, using GTK (a popular and portable GUI framework for C), you can have code like this: void callback(GtkWidget *widget, gpointer data) { g_print("Hello world!\n"); } int main(int argc, char **argv) { GtkWidget *button; /* do some initialization - omitted here */ gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC (callback), NULL); /* start the event loop - when button is clicked, callback will be * invoked */ gtk_main(); return 0; } |
|
![]() |
| Outils de la discussion | |
|
|