Null references (oh no, not again!)
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Wed Mar 4 07:53:42 PST 2009
Don wrote:
> Andrei Alexandrescu wrote:
>> And there is no reference type with two subtypes. It's one type in the
>> language and one in the library. Maybe-null (the library) is a
>> supertype of non-null (the default).
>
> One problem I can see is with extern(C),(Windows) functions, since
> pointers are maybe-null in C. The name-mangling has to work out.
> I can't see how this can be done without the compiler knowing SOMETHING
> about both nullable and non-nullable types.
> At the bare minimum, you need to deal with maybe-null returns and
> reference parameters from C functions.
Walter is thinking of making only references non-null and leaving
pointers as they are. (I know, cry of horror.) But say pointers are also
non-null. Then:
extern(C) MaybeNull!(void*) malloc(size_t s);
will work, provided that MaybeNull has no size overhead and that
word-sized structs are returned in the same register as word returns (I
seem to remember Walter told me that's the case already).
> Incidentally, uses of maybe-null in immutable types must be _extremely_
> rare. The usage statistics for D are likely to be skewed towards
> non-null types, compared to Java. I'd say the 66% is a very conservative
> lower bound.
Very good point. With a mutable null pointer, there's at least hope it
will become something interesting later :o).
Andrei
More information about the Digitalmars-d
mailing list