I work on data processing which works with layered data.
The best analogy to my current work is that of network processing. Packets are layered and each layers is processed individually by a specicialized function. The next function to call for a deeper layer is calculated in the current layer. Under some circumstances it can happen that the callstack shows recursive behviour in a way that a previously called function is called again (eg. A()->B()->C()->B()->D()...)
Currently I do that in the following way:
void func_N(void)
{
// get next layer info
switch (next) {
case A:
func_A();
break;
case B:
func_B();
break;
default:
finalize()
}
}
I can guarantee that the call chains do not become arbitrarily long. There is a technical limit, although pretty high. The depth of the callstack is dependent on the data which we can make some assumptions about. I'd need to get some fresh statistics, but a maximum depth of 10 calls would be a good estimate.
I hope you get the idea. Works fine, but the more complex the potential trajectories through the call stack become, the harder this gets to maintain.
However, maintainability is not my primary concern. In this case, performance is. Are there other, faster, better suited programming techniques for this problem?