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?
In the Rationale for the C99 Standard, page 24, discussing translation limits:
Provided that there exists at least one--possibly contrived and useless--program that nominally exercises the given translation limits, and that an implementation will process in a fashion consistent with the Standard, nothing the implementation does with any other program could render it non-conforming. Thus, it's not actually possible for any program to meaningfully avoid Undefined Behavior, but the authors of the Standard expected that most implementations would focus more on what would be necessary to make them useful, rather than on trying to do the bare minimum required by the Standard.