It can be hardly possible.
Use the coroutine library. In doing so, you allocate your own stack from the heap. Rebuild your code to keep track of how deep it is in its stack, and when it gets dangerously deep, create a new cothread and switch to it. When you run out of heap memory, freeze old cothreads and free their memory. Of course, you should definitely unfreeze them at the same address - so I suggest you lay out your stacks from your own arena so that you can control. It may actually be easier to just reuse the same piece of memory for the cothread stack and swap them every time.
Of course, you can rewrite your algorithm as non-recursive.
This can be an example of his work, or he can simply print the correct answer in case of an accident:
#include <stdio.h>
Now you just need to determine how much memory is in the system, how much of it is available, how big the column is, and when the callstack is exhausted, so you know when to deploy an infinite stack. This is not an easy task for one system, not to mention its portability. Perhaps it would be better to learn how to actually use the stack, rather than fight it.
source share