Safe mode in D?

John Colvin john.loughran.colvin at gmail.com
Fri Oct 18 02:10:29 PDT 2013


On Friday, 18 October 2013 at 06:26:51 UTC, Maxim Fomin wrote:
> On Thursday, 17 October 2013 at 23:25:52 UTC, Meta wrote:
>> On Thursday, 17 October 2013 at 23:18:21 UTC, DDD wrote:
>>> I tried this code and the compiler allowed it (runtime I get 
>>> object.Error: Access Violation). What am I doing wrong?
>>>
>>> Thanks I didn't notice
>>>
>>> @safe
>>> import std.stdio;
>>> class A {
>>> 	int x  = 1;
>>> }
>>> @safe void main() {
>>> 	A a;
>>> 	a.x=9;
>>> }
>>
>> This is more or less a different thing. SafeD doesn't 
>> guarantee that your class references will not be null. Trying 
>> to call a method on a null reference is perfectly valid in 
>> SafeD. There's a pull request sitting in GitHub for a NotNull 
>> type that should be reasonable good for ensuring that your 
>> references are not null, but it hasn't been pulled yet.
>
> Actually on linux this will segfault so in general this is not 
> safe across all platforms.

It's still memory safe in the sense that it's guaranteed to not 
stomp on anything -> no silent corruption.

I don't really think the distinction between an Error or a 
segfault is the dividing line between safe and not safe. Both are 
supposed to be (under 99.9% of circumstances) unrecoverable 
errors.


More information about the Digitalmars-d mailing list