How does D handle null pointers?

bearophile bearophileHUGS at lycos.com
Mon Aug 23 14:09:32 PDT 2010


Adam B:
> 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
> }

Your example is not particularly well chosen, D arrays are not really references, they are fat, two words long.

Bye,
bearophile


More information about the Digitalmars-d mailing list