Phobos for Review: std.buffer.scopebuffer

Marco Leise Marco.Leise at gmx.de
Sat Feb 8 20:14:41 PST 2014


Am Sat, 08 Feb 2014 02:13:18 -0800
schrieb Walter Bright <newshound2 at digitalmars.com>:

> On 2/7/2014 4:59 PM, Andrei Alexandrescu wrote:
> > On 2/7/14, 3:11 PM, Brad Anderson wrote:
> >> On Friday, 7 February 2014 at 23:10:50 UTC, Walter Bright wrote:
> >>> On 2/7/2014 2:14 PM, Brad Anderson wrote:
> >>>>
> >>>> There's always alloca :)
> >>>
> >>> alloca() cannot be used to allocate stack data in a function enclosing
> >>> the current one.
> >>
> >> Oh, right. Forgot about that.
> >
> > You can with a default parameter...
> >
> > void fun(void* sneaky = alloca(42));
> >
> > will allocate memory on fun caller's frame and make it available to fun.
> 
> I think there's a bit of a problem in how the user specifies the 42?

It depends on what syntax you expect. I solved it this way:

void fun(alias length)(void* sneaky = alloca(length));

void foo()
{
    size_t myLength = 42;
    fun!myLength();
}

-- 
Marco



More information about the Digitalmars-d mailing list