Below is part of the source code of an allocator from the sgistl(2.91.57)

void ( *set_malloc_handler( void(*f)() ) ) ()

The purpose of this function is mimic the behavior of set_new_handler.
But i don't know what is the meaning of this function.

return type = void
name = ?
parameter lists = () ?

Thank you very much

Edited by stereomatching: n/a

5 Years
Discussion Span
Last Post by stereomatching

Looks like its all about function pointer.
But I think your code has little bit definition issue?
If I am right it should be like this:

typedef void ( *set_malloc_handler)( void(*f)() ) ;
//Which means set_malloc_handler is a function pointer, which takes another function pointer as argument.

Here is an example below:

#include <iostream>

typedef void ( *set_malloc_handler)( void(*f)() ) ;

void firstFun( void(*f)() ){

void callme(){
	std::cout << "Call me" << std::endl;
int main() {
	set_malloc_handler myfun = firstFun; //myfun is a function poitner vairbale of type set_malloc_handler, and its value is firstFun

Output of this function is:
Call me

Edited by alwaysLearning0: n/a


Thanks to both of you

But I think your code has little bit definition issue?

no, but your version is much more easier to understand(IMHO).
They have the same meaning, the link of gerard4143 post explain it well.
Man, I never know I could return a function pointer like that
I like the version of typedef better

Thanks a lot

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.