Generic and fundamental language design issue
Tommi
tommitissari at hotmail.com
Sun Nov 4 11:57:42 PST 2012
On Sunday, 4 November 2012 at 19:42:29 UTC, Tommi wrote:
> void func(T)(int n)
> {
> if (n <= 0)
> return;
>
> auto t = <create variable t of type T>
> ...
> func!(T)(n - 1);
> }
>
> If func is called with a runtime argument n, then the
> programmer cannot determine the most sensible way to allocate
> for variable t.
The reason for that being that if n is large enough and t gets
always allocated on stack, then there's going to be a stack
overflow. And if n is small enough so that all those t's could be
allocated on stack, then allocating them on heap would just make
the code slower.
More information about the Digitalmars-d
mailing list