Function without name

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





This is a pointer on function...
– Jarod42
Sep 3 at 14:08




2 Answers
2



It isn't a function. It's a declaration saying that _malloc_message is a pointer to a function, with return type void and the parameters as given.


_malloc_message


void



In order to use it, you'd have to assign to it the address of a function with that arity, return type, and parameter types.



Then you'd use _malloc_message as if it were a function.


_malloc_message





What if there would be two functions which return type void and the parameters given?
– Chyu
Sep 3 at 14:19






Well you'd hope that _malloc_message would point to one of them, depending on conditions apparent by inspecting the program.
– Bathsheba
Sep 3 at 14:20


_malloc_message



_malloc_message is a function pointer.


_malloc_message



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


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;


_malloc_message = foo;



and call it like this:



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


(*_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.





It is not my code. I'm trying to learn advanced C++ by reading somebody else code. There are all those steps except a calling one. That is interesting, maybe the function is no longer used in that code and author forgot to delete it.
– Chyu
Sep 3 at 14:33






@Chyu • there are several good books on learning advanced C++. Here is a curated list of books: stackoverflow.com/questions/388242/…
– Eljay
Sep 3 at 14:52





@Chyu The call might be hidden in a macro. Also, since it's declared extern, it might be called from a different compilation unit.
– Barmar
Sep 3 at 22:14


extern



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế