| ▲ | RealityVoid 2 days ago | ||||||||||||||||||||||||||||||||||||||||||||||
Your points are correct, but recursion is banned anyway in safety critical applications. The main issue is determinism. The fact you have to use the stack for call stacks is correct OP seems misinformed. | |||||||||||||||||||||||||||||||||||||||||||||||
| ▲ | adrian_b 2 days ago | parent [-] | ||||||||||||||||||||||||||||||||||||||||||||||
You have to use the stack for procedure calls on x86/x86-64 CPUs, where the hardware enforces this. In most other surviving CPU ISAs the return address is saved in a register and it is easy to arrange in a compiler to use only procedure arguments that are passed in registers, the only price being paid for this being a reasonable upper limit for the number of parameters of a function, e.g. 12 or 24, depending on the number of general-purpose registers (e.g. 16 or 32). For the very rare case when a programmer would want more parameters, some of them should be grouped into a structure. With this convention, which normally should not be a problem, there is no need for a call stack. There can be software managed stacks, which can be used even for implementing recursion, when that is desired. The use of static memory for passing function arguments was necessary only in the very early computers, which were starved in registers. | |||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||