On Wed, 04 Mar 2009 19:39:06 +0300, Don <nos...@nospam.com> wrote:

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.

extern(System) int GetTextCharsetInfo(
        HDC hdc,
        MaybeNull!(FONTSIGNATURE*) lpSig, // or whatever
        DWORD dwFlags);

GetTextCharsetInfo(hdc, null, flags); // fine
GetTextCharsetInfo(hdc, &sig, flags); // also ok

Reply via email to