typedef struct {
void *a;
void (*callback)(void *);
} callback_t;
void g( void *a )
{
printf("%s\n", (char *)a);
}
int setcallback( callback_t **pp, void (*callback)(void *), void *a )
{
callback_t *p;
p = malloc( sizeof(callback_t) );
p->a = a;
p->callback = callback;
*pp = p;
return 0;
}
int unsetcallback( callback_t *p )
{
free(p);
return 0;
}
int runcallback( callback_t *p )
{
(p->callback)( p->a );
return 0;
}
char *hoge="abcde";
main()
{
callback_t *p;
setcallback( &p, g, (void *)hoge );
runcallback( p );
unsetcallback( p );
return 0;
}