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

Kirk McDonald kirklin.mcdonald at gmail.com
Thu Feb 1 01:06:03 PST 2007


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.

You can't pass it null, for the same reason that you can't pass null to 
a C++ function with a reference parameter.

I would recommend binding the C API as closely as you can, and then 
using D's features in a wrapper around it. Generally speaking, this will 
be the most robust and portable approach. It will give you the 
convenient D version for most uses, and the raw C version when you need 
that.

-- 
Kirk McDonald
Pyd: Wrapping Python with D
http://pyd.dsource.org


More information about the Digitalmars-d-learn mailing list