3 ms·
It's sad that recursion is considered dangerous. Tail calls have been known about for a very long time, and the duality between stack and heap for just about as
by noelwelsh 13y ago
It's sad that recursion is considered dangerous. Tail calls have been known about for a very long time, and the duality between stack and heap for just about as long.
- Peaker 13y agoEven if you allow tail recursions, you still may want to disallow general recursions.
- reeses 13y agoTail calls are only helpful if optimized into jumps instead of function calls.
- pnathan 13y agoAnd this only happens if your compiler will recognize it. Not all compilers are smart enough. And embedded compilers often don't have the love that mainstream compilers get. In the absence of specific & concrete evidence that your compiler does this optimization and that you have and will tested this (including checking the emitted assembly code), it is correct to assume that TCO does not happen and to perfom stack depth analyses based upon that.
- pessimizer 13y agoIf you also built the computer, wouldn't you already have that specific and concrete evidence?
- pnathan 13y agoBeg pardon? I don't know what you mean. Most embedded companies purchase a chip... sometimes the compilers come from the same company that made the chip, sometimes not. Regardless, it's the engineer's responsibity to not assume about such a critical part of the design.
- hvidgaard 13y agoRecursion is a tool, and like any other tool, you can use it to destroy the windows. It's not more or less dangerous than string manipulation in C. Transforming recursive algorithms to tail calls only isn't always an option, or it makes the algorithm unnecessarily complex. The problem here is that in any critical control unit, recursion must be verified safe and/or there must be an external measure to detect and recover from stack overflows.