-1

I'm experiencing a segfault when recursing a pointer function.

#include <stdio.h>

int func(int(*function)()) {
    (*function)();
    func(function);
};

int function() {

};

int main() {
    func(function);
};

When compiled and executed, the recursive function calls last for a few cycles and then throw a segfault. Any ideas on how to fix this?

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Borys
  • 1

1 Answers1

1

More likely than not, you simply ran out of space in your stack frame because your function will recurse forever.

Bill Lynch
  • 80,138
  • 16
  • 128
  • 173