purity and memory allocations/pointers
Meta
jared771 at gmail.com
Sat Aug 3 12:07:47 PDT 2013
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).
More information about the Digitalmars-d
mailing list