PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.c > callback functions
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
callback functions

Réponse
 
LinkBack Outils de la discussion
Vieux 11/04/2008, 09h25   #1
prashant.khade1623@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut callback functions

What are callback function ?

how are they implemented and where they are useful ?

what are the advantages of function pointer ?
  Réponse avec citation
Vieux 11/04/2008, 09h41   #2
Ian Collins
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: callback functions

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.
  Réponse avec citation
Vieux 11/04/2008, 09h43   #3
prashant.khade1623@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: callback functions

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
  Réponse avec citation
Vieux 11/04/2008, 09h49   #4
Richard Heathfield
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: callback functions

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
  Réponse avec citation
Vieux 11/04/2008, 09h54   #5
Chris Thomasson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: callback functions

<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...

  Réponse avec citation
Vieux 11/04/2008, 09h56   #6
Ian Collins
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: callback functions

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.
  Réponse avec citation
Vieux 11/04/2008, 10h05   #7
Richard Heathfield
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: callback functions

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
  Réponse avec citation
Vieux 11/04/2008, 11h20   #8
Antoninus Twink
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: callback functions

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;
}

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h05.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,14846 seconds with 16 queries