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

Charles Srstka cocoadev at charlessoft.com
Thu Dec 24 00:56:50 CST 2015


> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151224/898b0af8/attachment.html>


More information about the swift-evolution mailing list