I want to understand what this code means actually, esp. the last part where the function is put into curly braces. Is the broadcast_open function somehow calling the function broadcast_recv? If yes, how?
static void broadcast_recv(struct broadcast_conn *c, const rimeaddr_t *from)
{
printf("broadcast message received from %d.%d: '%s'\n",
from->u8[0], from->u8[1], (char *)packetbuf_dataptr());
}
static const struct broadcast_callbacks broadcast_call = {broadcast_recv};
static struct broadcast_conn broadcast;
PROCESS_THREAD(example_broadcast_process, ev, data)
{
broadcast_open(&broadcast, 129, &broadcast_call);
...
}
void broadcast_open(struct broadcast_conn *c, uint16_t channel, const struct broadcast_callbacks *u)
{
abc_open(&c->c, channel, &broadcast);
c->u = u;
channel_set_attributes(channel, attributes);
}
You have probably seen simple variables initialized, e.g.:
When it’s an aggregate, such as a structure, braces are used around the initializer so the compiler knows where the initializer ends. In this case, it would appear that a function pointer is the first member of the struct.
Someone can now call
f()with(*a_t_instance.f)(), or evena_t_instance.f()So yes,
broadcast_openor something that it calls is probably callingbroadcast_receive,using the pointer in the structure.