Uh... destructors?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Feb 23 07:35:26 PST 2011


On 2/23/11 9:00 AM, Steven Schveighoffer wrote:
> On Wed, 23 Feb 2011 08:04:49 -0500, Andrei Alexandrescu
> <SeeWebsiteForEmail at erdani.org> wrote:
>
>> On 2/22/11 3:14 PM, Steven Schveighoffer wrote:
>>> On Tue, 22 Feb 2011 15:48:42 -0500, %u <wfunction at hotmail.com> wrote:
>>>
>>>>> D pure functions are significantly different than this definition
>>>> (as of recent times, when weak-pure was added).
>>>>> Essentially, a pure function cannot access global variables.
>>>> However, it can access variables referred to via a member of the
>>>> object instance.
>>>>> i.e. this is a valid pure function:
>>>> class C
>>>> {
>>>> int x;
>>>> pure void foo() { x++; }
>>>> }
>>>>
>>>> I... did not know that. But even in that case, pure wouldn't make much
>>>> sense, because doing anything like freeing memory or closing a file
>>>> handle affects global variables (whether directly in the runtime or
>>>> indirectly in the OS)... right?
>>>
>>> Freeing and allocating memory is fair game for pure functions.
>>
>> I don't think freeing memory is pure.
>
> Why not? If it shouldn't be allowed, it should be easy to show with an
> example of why.
>
> -Steve

free(p) affects data remotely outside the pure function.

Andrei


More information about the Digitalmars-d mailing list