You are not logged in.
Pages: 1
Hi All,
Though I have seen these types of coding with callback structures several times but still few things are beyond my intuition.
Can some body explain me few points here?
1) Why function pointer "fp" passes reference of struct "node" itself ?
2) Who is passing values to "data" parameter to function "my_node" here ? (see arrow in code)
3) It seems there is a duplicate info. printed by function "my_node". Is this correct ?
4) Is this correct way of defining and calling callback structures?
struct node
{
void (*fp)(struct node*, void*);
void *data;
};
struct node saved = { 0, 0 };
void node_register(void (*fp)(struct node*, void*), void *user_data)
{
saved.fp = fp;
saved.data = user_data;
}
void my_node(struct node *nd, void *data) ==============> Who is passing values to "data" parameter here ?
{
printf("Inside function... %s\n", __func__);
printf("data1: %s\n", (char *)data);
printf("data2: %s\n", (char *)nd->data);
}
main(void)
{
node_register(my_node, "Hello");
saved.fp(&saved, saved.data);
}
Thanks.....................
Offline
Pages: 1