The only alloca()
replacement for C++ I have found on the Internet looks something like this:
template <typename F>
void alloca_(::std::size_t const n, F&& f) noexcept(noexcept(f({})))
{
alignas(::std::max_align_t) char p[n];
f(p);
}
But, obviously, this is not the alloca()
we know and love, it is not a function, nor a macro. Can an alloca()
implementation that resembles the alloca()
function call semantics more closely, be written? Perhaps as a macro? Whether macro or function, it should allocate space from the stack, not the heap.