Are null refs intentionally allowed?

Dukc ajieskola at gmail.com
Sat Jul 16 12:33:57 UTC 2022


This compiles and runs just fine, printing what you'd except:

```D
@safe void main()
{
     import std.stdio;

     int* p;
     isNull(*p).writeln;
     p = new int(5);
     isNull(*p).writeln;
}

@safe bool isNull(ref int x){return &x is null;}
```

The question is, is this intentional? I'm writing "DIP1000: 
Memory Safety in a Modern System Programming Language Pt. 2" and 
currently I've written that this is allowed, even when it's not 
in C++.

But there are still two possibilities: either this is okay by 
design, or works by accident but really disallowed. Which is the 
case?


More information about the Digitalmars-d mailing list