解析SGI STL 函数static void (* __set_malloc_handler(void (*__f)()))()
static void (* __set_malloc_handler(void (*__f)()))() { void (* __old)() = __malloc_alloc_oom_handler; __malloc_alloc_oom_handler = __f; return(__old); }
首先必须知道作为参数的函数指针和返回函数指针的函数表示方式(见Function
Pointer)。
故而可知void (*set_malloc_handler())()表示set_malloc_handler为返回值为void (*f)()形式的函数指针的函数。
其次void (*__f)()仅仅是一个函数参数。
综上可知:void (* __set_malloc_handler(void (*__f)()))()是一个函数,它接受一个形式为void (*__f)()的函数指针作参数,
并且返回一个形式为void (*__f)()的函数指针。写成易懂的形式就是
typedef void(*pt2Func)(); pt2Func __set_malloc_handler( void (*__f)() ) { void (* __old)() = __malloc_alloc_oom_handler; __malloc_alloc_oom_handler = __f; return(__old); }