purity and memory allocations/pointers
monarch_dodra
monarchdodra at gmail.com
Sat Aug 3 14:19:33 PDT 2013
On Saturday, 3 August 2013 at 19:07:49 UTC, Meta wrote:
> On Saturday, 3 August 2013 at 16:47:52 UTC, Timon Gehr wrote:
>> On 08/03/2013 05:59 PM, monarch_dodra wrote:
>>> One last question: Pointers.
>>>
>>> int get(int* p) pure
>>> {
>>> return *p;
>>> }
>>>
>>> void main()
>>> {
>>> int i = 0;
>>> auto p = &i;
>>> get(p);
>>> }
>>>
>>> Here, get, to me, is obviously not pure, since it depends on
>>> the state
>>> of the global "i". *Where* did "get" go wrong? Did I simply
>>> "abusively"
>>> mark get as pure? Is the "pure" keyword's guarantee simply
>>> "weak"?
>>> ...
>>
>> Yes, it's weak.
>
> It depends on whether you think a pointer dereference is pure
> or not (I don't know the answer). That aside, as long as get
> doesn't modify the value at *p or change what p points to, this
> is strongly pure (i.e., the academic definition of purity).
Thank the 3 of you for your answers. I think I had a wrong
preconception of what pure is. I think this cleared most of it up.
More information about the Digitalmars-d
mailing list