Safety, undefined behavior, @safe, @trusted

Steven Schveighoffer schveiguy at yahoo.com
Thu Nov 5 18:27:46 PST 2009


On Thu, 05 Nov 2009 21:17:08 -0500, Walter Bright  
<newshound1 at digitalmars.com> wrote:

> Steven Schveighoffer wrote:
>> But what if I don't what the whole function to be trusted, just that  
>> creation section?  I have to create a new function just to create the  
>> data?
>
> Separate out the trusted code to a separate function.

Although that's a solution, it seems artificial to have to build a  
separate function just to allocate some immutable object.  If unsafe code  
is truly going to be a rare occurrence, you might want to allow as fine  
grained control as possible over where the compiler ignores safety.   
Having to create artificial boundaries that cause performance  
problems/code bloat doesn't seem right to me.

However, I'll let it go, I don't know the ramifications since allocating  
immutable objects is a rare occurrence, and I'm not sure how it will be  
done.  I am also not sure how solid a use case this is (allocating an  
object, then manipulating it via methods before changing it to immutable).

-Steve



More information about the Digitalmars-d mailing list