Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function without name

I would like to know how to call this function? And where can i find it's implementation if it doesn't have name?

extern void (*_malloc_message)(const char* p1, const char* p2, const char* p3, const char* p4);
like image 824
Filip Falcon Avatar asked Sep 03 '18 14:09

Filip Falcon


1 Answers

_malloc_message is a function pointer.

Somewhere in the code you will find the definition of a function whose prototype is like this:

void foo (const char* p1, const char* p2, const char* p3, const char* p4);

Then you assign the function to the function pointer like this:.

_malloc_message = foo;

and call it like this:

(*_malloc_message)(p1, p2, p3, p4);

The question is why you cannot call foo directly. One reason is that you know that foo needs to be called only at runtime.

like image 183
P.W Avatar answered Oct 03 '22 02:10

P.W