How does D handle null pointers?

Adam B cruxic at gmail.com
Mon Aug 23 13:30:15 PDT 2010


I was pondering bearophile's idea of having compile-time null
checking.  Since adding new language syntax is often a hard thing to
sell to the language authors, perhaps we could get by with just a
compiler warning?  Some static code analysis.  For example:

--------------
char[] foo()
{
       if (some condition)
            return "yada";
       else
               return null;   //compiler makes note that foo() might return null
}

void bar()
{
     char[] s = foo();
     printf(s);   //compiler issues warning because 's' has not been
null-checked
}
--------------

Or, if that's too heavy for the compiler, it could be done in a
separate program.  (Is there a Lint like program for D?)

On Sat, Aug 21, 2010 at 4:59 AM, bearophile <bearophileHUGS at lycos.com> wrote:
> Richard Webb:
>
>> I think that bearophile suggested that references be marked as non-nullable
>> because making them non-nullable by default is a breaking change in the language
>> (i agree that that is a better approach though).
>
> Right. I think at this point there's no hope to non-nullable by default. But the solution in two parts that I have suggested may be good enough, I don't know.
> I'd like to be able to create a D2 experimental version with those changes, to try how it works in practice on few small programs.
>
> Bye,
> bearophile
>


More information about the Digitalmars-d mailing list