Safe mode in D?

Maxim Fomin maxim at maxim-fomin.ru
Thu Oct 17 23:26:47 PDT 2013


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.


More information about the Digitalmars-d mailing list