Is this function pure?

Janice Caron caron800 at googlemail.com
Tue Sep 18 09:29:12 PDT 2007


On 9/18/07, OF <nospam at nospammington.com> wrote:
> Problems arise as long as you allow new to fail like this or if you use the address you get (which of course is not deterministic to the degree we want).

I think the "address of" operator would have to banned completely from
pure functions, otherwise you could do

int definitelyNotPure()
{
    int x;
    return cast(int)&x;
}


> Probably it's best to leave memory allocations to implicit allocations in pure functions, but this is tricky if you want to return a new object as a modified version of an input object. I don't know how it's intended for D to solve this nicely, but I'm very interested in hearing it.

The only way I can think of is the old-fashioned C way, of passing a
buffer and a length (or in D, an array) into the function, and using
that and that alone as your memory.

...Ooooh, but wait - don't all inputs have to be (transitively) const!?

Yikes.



More information about the Digitalmars-d mailing list