Using out qualifier instead of *, how to pass null?

xs0 xs0 at xs0.com
Thu Feb 1 15:38:30 PST 2007


Derek Parnell wrote:
> On Thu, 01 Feb 2007 03:00:01 -0500, Rick Mann wrote:
> 
>> In wrapping this C API, I've been going back and forth
>> between converting "Foo*" output parameters to "out Foo". 
>> I prefer the latter, as I don't have to take the address
>> at the call site, but I don't seem to be able to pass null
>> (which the API allows, meaning, "I'm not interested in
>> this return value").
>>
>> Am I just stuck with Foo*? Alternatively, I can overload
>> the C function with D wrappers, I suppose. Hmm. That's
>> probably best.
> 
> Is not possible to use a 'null' object ... ?
> 
> 
> class Foo {}
> void Bar(out Foo f) 
> { 
>   if (f is null)
>       ...  
>   else
>       ...
> }
> Foo NullFoo;
> Foo RealFoo = new Foo;
> 
> Bar(NullFoo);
> Bar(RealFoo);

hmm.. doesn't out cause (f is null) to be always true in that code?


xs0


More information about the Digitalmars-d-learn mailing list