Null references redux

Denis Koroskin 2korden at gmail.com
Wed Sep 30 12:30:02 PDT 2009


On Wed, 30 Sep 2009 23:08:40 +0400, Jarrett Billingsley  
<jarrett.billingsley at gmail.com> wrote:

> On Wed, Sep 30, 2009 at 12:44 PM, bearophile <bearophileHUGS at lycos.com>  
> wrote:
>> Max Samukha:
>>
>>> Don't get confused by 'new' in struct initializers. Structs in C# are
>>> value types.
>>
>> Yes, you are right.
>>
>> But in D structs can be allocated on the heap too, so I think having  
>> optional nonnull struct pointers can be useful. The syntax and usage is  
>> similar to normal struct pointers.
>
> I don't know why a struct pointer would be different than any other
> pointer. That is, you'd have S* and S*? as well as int* and int*?.

Note that C stdlib (and other libraries/bindings) will need to be updated  
to reflect changes, e.g.

extern(C) void*? malloc(size_t size); // may return null!

which is great because it will provide additional safety. I've seen quite  
a lot of code that don't test returned value against null (which is a  
mistake, I believe).



More information about the Digitalmars-d mailing list