Drew McGowen Drew McGowen - 5 months ago 26
C Question

Function Returning Itself

Is it possible to declare some function type

which returns that type,

In other words, is it possible for a function to return itself?

// func_t is declared as some sort of function pointer
func_t foo(void *arg)
return &foo;

Or would I have to use
void *
and typecasting?


No, you cannot declare recursive function types in C. Except inside a structure (or an union), it's not possible to declare a recursive type in C.

Now for the void * solution, void * is only guaranteed to hold pointers to objects and not pointers to functions. Being able to convert function pointers and void * is available only as an extension.