Uh... destructors?

Steven Schveighoffer schveiguy at yahoo.com
Wed Feb 23 07:57:45 PST 2011


On Wed, 23 Feb 2011 10:46:43 -0500, Andrei Alexandrescu  
<SeeWebsiteForEmail at erdani.org> wrote:

> At a level it's clear to me that a function cannot be at the same time  
> pure and unsafe. For example:
>
> pure void foo(int *x) { free(x); (*x)++; }
>
> This function essentially breaks any guarantee for the entire program,  
> so it would be quite difficult to claim it's pure.

I thought @safe was orthogonal to pure?  If this isn't the case, then yes,  
free must be disallowed.  But then malloc must also be, and any construct  
which manages its own memory via malloc/free.

 From what I remember, pure functions:

1. cannot access shared or global non-immutable data
2. cannot call non-pure functions

I don't remember the definition that pure functions must also be @safe.

-Steve


More information about the Digitalmars-d mailing list