[swift-users] Why does withUnsafePointer(to:) require a var argument?

Florent Bruneau florent.bruneau at intersec.com
Thu Apr 27 01:31:07 CDT 2017

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
> https://lists.swift.org/mailman/listinfo/swift-users

Florent Bruneau

More information about the swift-users mailing list