[swift-users] Why does withUnsafePointer(to:) require a var argument?
Rien at Balancingrock.nl
Thu Apr 27 01:37:27 CDT 2017
1) When you obtain a pointer, it can no longer be ensured by the compiler that you won’t write to it.
2) A ‘let’ variable (constant) allows way more optimizations than a ‘var’. I would not be surprised if the majority of ‘let’ constants never see any memory allocation at all.
Project: http://swiftfire.nl - A server for websites build in Swift
> On 27 Apr 2017, at 08:31, Florent Bruneau via swift-users <swift-users at swift.org> wrote:
> Hi Rick,
> My understanding on this is that withUnsafePointer() requires an inout argument because it has to take a reference to the variable in order to be able to derive its pointer. The languages requires inout arguments to be vars, leading to withUnsafePointer() requiring the passed object to be a var.
> There may be other subtleties I'm not aware of, though.
>> Le 27 avr. 2017 à 02:42, Rick Mann via swift-users <swift-users at swift.org> a écrit :
>> We have withUnsafePointer(to:) and withUnsafeMutablePointer(to:). Why does the first take an inout parameter? The function names imply that the first will not modify the pointer (which I take to mean its contents), and it makes it quite clunky to pass in constant things.
>> Rick Mann
>> rmann at latencyzero.com
>> swift-users mailing list
>> swift-users at swift.org
> Florent Bruneau
> swift-users mailing list
> swift-users at swift.org
More information about the swift-users