Call Stack Alternatives
Discussions focus on the use of stacks for function calls in compilers like C, stack overflows versus smashing, and alternatives such as heap-allocated frames, growable or segmented stacks, and stackless implementations.
Activity Over Time
Top Contributors
Keywords
Sample Comments
The way most C compilers and ABIs use the stack kills it imo. But you could tweak a compiler to change that.
Sure it is. Stack space isn't free
The C standard does not mention a stack. One can implement a C compiler that puts activation records on the heap or does other magic to avoid a stack that can overflow. A call stack is an implementation detail. Expecting it to exist or not exist is assuming things about the compiler. Those assumptions may be reasonable but are not part of the semantics of the language itself. They are about particular properties of your compiler.
They can overflow the stack. They cannot smash the stack.
Function calls don't necessarily need to use stacks. There is nothing preventing frame allocations on heap.
Would the segmented stack of the early Go implementations be helpful in such a case?
If we had standardized growable call stacks then this wouldn't happen
Stack was pretty small. Allocating structure on the heap instead of on the stack is pretty standard. We just need to understand the historic context before making judgement.
The runtime could allocate "stack frames" on the heap, for such cases.
Function calls use stacks. It is not the same thing as heap allocation.