On Saturday, 21 April 2018 at 07:57:41 UTC, Uknown wrote:
The language itself doesn't have something, but you could use
`alloca`
I don't know if this little template function makes life easier:
------
pragma(inline, true)
ref T push(T)(size_t len)
{
import core.stdc.stdlib, core.stdc.stdio;
return *cast(T*)alloca(T.sizeof * len);
}
void doSomething(size_t len)
{
auto stackBuffer = push!char(len+1);
stackBuffer[0] = 'H';
stackBuffer[1] = '\0';
printf("%.*s", stackBuffer.ptr);
}
void main()
{
doSomething(2);
}
------