If the stack size in C is an implementation detail, and stack overflow is undefined behavior, is is possible whatsoever to perform any recursion at all without the possibility of summoning nose demons?
If I traverse through a data structure recursively, to give a naïve example:
struct tree {
int leaf;
struct tree *left;
struct tree *right;
}
struct tree *get(const struct tree *t, int i) {
if (t == NULL) return NULL;
return i == t->leaf ? t : (i > t ? get(t->right) : get(t->left));
}
Is there some sort of check that can be implemented so that this example can run safely on any standards-following C compiler, is there some sort of macro for that, or is it completely impossible, and there is no way to make this example or any similar pattern safe?