Null references (oh no, not again!)

Don nospam at nospam.com
Wed Mar 4 08:39:06 PST 2009


Andrei Alexandrescu wrote:
> 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).

Here's a typical annoying Windows API function
--------
int GetTextCharsetInfo(
   HDC hdc,                // handle to DC
   LPFONTSIGNATURE lpSig,  // data buffer
   DWORD dwFlags           // reserved; must be zero
);

lpSig
[out] Pointer to a FONTSIGNATURE data structure that receives 
font-signature information. The lpSig parameter can be NULL if you do 
not need the FONTSIGNATURE information.
---------
How do you do this?

Don.



More information about the Digitalmars-d mailing list