Recursively declare a function in C

got a question from adream307, i have no idea how about yours?

I want to declare a function like this: (we named this type of function as F)

  • return type F is "void"
  • parameter F is a pointer to a function, this pointer indicates a function whose type is the same as F

Is it possible to declare such a function?

+3
source share
1 answer

No, you can’t. A type cannot be expressed because it repeats:

void f(void g(void h(...

But you can write a function that accepts itself without any problems. Consider

void f(void g()) { }

int main(void) { f(f); }

. f (void g() void (*g)()), f. f, void() void (void()) :

[ ], , [ ], , , .

, .

+7

All Articles