Nullable types

Lionello Lunesu lionello at lunesu.remove.com
Mon Oct 20 18:33:40 PDT 2008


"Bill Baxter" <wbaxter at gmail.com> wrote in message 
news:mailman.176.1224549806.3087.digitalmars-d at puremagic.com...
> On Tue, Oct 21, 2008 at 9:35 AM, Bill Baxter <wbaxter at gmail.com> wrote:
>> On Tue, Oct 21, 2008 at 9:11 AM, Lionello Lunesu <lio at lunesu.remove.com> 
>> wrote:
>>> Bent Rasmussen wrote:
>>>>
>>>> Not true. It wraps the value type in a struct with a boolean field
>>>> expressing whether it is null or not.
>>>>
>>>> http://msdn.microsoft.com/en-us/library/1t3y8s4s(VS.80).aspx
>>>
>>> Indeed. Thanks for pointing that out.
>>>
>>> So C#'s 'foo?' syntax has even less to do with this compile-time 
>>> nullness
>>> checking.
>>
>> Now it makes sense.  Yes the C# feature is apparently just a
>> convenient way to create a value type with a special
>> "none-of-the-above" value.
>> I guess this feature is driven by need to connect with databases that
>> often have nullable types.
>>
>> This chapter of a C# 2.0 book covering Nullable Types seems to agree
>> with that assessment :
>> http://www.springerlink.com/content/w2mh0571776t3114/
>
> Also C++ has *non*-Nullable types in the form of references.
>
> void aFunction(ref Struct xyz) {
>     // &xyz is a pointer that can't be null
> }
>
> ref Struct anotherFunction() {
>    ...
> }
>
> &(anotherFunction()) --> can't be null
>
> I think that may be a C++ FAQ  for "When do I use references vs
> pointers?"  One answer to that is that if you don't want to allow
> NULLs, use a reference.  If you do, then use a pointer.

But C++ references behave very differently from non-null-references. For 
one, you can't change what is being referenced.

L. 




More information about the Digitalmars-d mailing list