[swift-evolution] Unmanaged, and COpaquePointer vs. Unsafe(Mutable)Pointer

Jordan Rose jordan_rose at apple.com
Tue Dec 8 18:30:57 CST 2015


> On Dec 8, 2015, at 16:03, Jacob Bandes-Storch <jtbandes at gmail.com> wrote:
> 
> Thanks, Jordan. I'll write one up tonight.
> 
> Should it use UnsafePointer or UnsafeMutablePointer?  I've seen that C APIs frequently get imported as UnsafeMutablePointer, when it doesn't necessarily match the semantics of the API. Is that just the default?

Either way we're going to lose in some cases. We can probably make the "from" case work for either, but I think the "to" case should just use UnsafeMutablePointer, because (a) "void *" is more common than "const void *" in C APIs*, and (b) if you do need to convert, "UnsafePointer(...)" is shorter. :-)

* citation needed

(Swift does support overloading on return type, but the downside is you need to always provide context, which makes it harder to break things up into multiple statements. So we generally avoid it unless there's a compelling reason.)

Jordan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151208/970d962c/attachment.html>


More information about the swift-evolution mailing list