[swift-evolution] Proposal: One-past-end array pointers and convertibility of nil for interaction with C APIs

Árpád Goretity arpad.goretity at gmail.com
Thu Dec 24 01:11:42 CST 2015


> The comments in the generated header for UnsafeMutablePointer claim that
its regular init() method constructs a null pointer.

That's right, and I have tried it as well. Yet, type inference doesn't like
like it, and I get back an error similar to what I have already described,
but this time with inout and UnsafeMutablePointer:

    result values in '? :' expression have mismatching types 'inout T' and
'UnsafeMutablePointer<T>'


On Thu, Dec 24, 2015 at 7:56 AM, Charles Srstka <cocoadev at charlessoft.com>
wrote:

> On Dec 23, 2015, at 7:50 PM, Félix Cloutier via swift-evolution <
> swift-evolution at swift.org> wrote:
>
>
> The & operator isn't exactly an address-of operator. Does &arr[0] even
> return a pointer to the inner buffer? When you use & with properties (and
> possibly with subscripts as well), Swift may create a local, copy the
> property value to it, pass a pointer to that local, and copy back the
> output to the property.
>
> Anyway, you are probably looking for
> Array.withUnsafe(Mutable?)BufferPointer:
>
> arr.withUnsafeMutableBufferPointer { foo($0, $0.count) }
>
> Félix
>
>
> The comments in the generated header for UnsafeMutablePointer claim that
> its regular init() method constructs a null pointer. Therefore, I think you
> should just be able to:
>
> foo(UnsafeMutablePointer<T>(), 0)
>
> Charles
>
>


-- 
Author of the Sparkling language
http://h2co3.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151224/9437cc7c/attachment.html>


More information about the swift-evolution mailing list