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

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)() ){
	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
	myfun(callme);
}

Output of this function is:
Call me

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.