Why does nobody seem to think that `null` is a serious problem in D?

NoMoreBugs NoMoreBugs at gmail.com
Tue Nov 20 02:44:23 UTC 2018


On Tuesday, 20 November 2018 at 00:30:44 UTC, Jordi Gutiérrez 
Hermoso wrote:
>
> Yeah, maybe this bit of C++ syntax isn't the best idea. What 
> about other alternatives?

You could try testing for null before dereferencing ;-)

If the following code in D, did what you'd reasonably expect it 
to do, then you could do this:

-----
module test;

import std.stdio;

class C { public int x; }

void main()
{
   try
   {
     C c = null;
     c.x = 100;
   }
   catch(Exception e)
   {
     writeln(e.msg);
   }

}
-----



More information about the Digitalmars-d-learn mailing list