[swift-evolution] [Discussion] Cleaning up stdlib pointer and buffer routines (Open Issues Affecting Standard Library API Stability)

Dave Abrahams dabrahams at apple.com
Thu Jul 7 18:01:31 CDT 2016


on Wed Jul 06 2016, Jacob Bandes-Storch <swift-evolution at swift.org> wrote:

>> * *Remove unsafeAddressOf*. "We are not aware of any real use cases for
>> it. If there are any, it should be renamed to unsafeAddress(of:) to follow
>> the guidelines." (https://bugs.swift.org/browse/SR-1957
>> rdar://problem/18589289)
>>
>>
> Oops, I just responded to this on another thread. Pasting:
>
> It's minor, but I use unsafeAddressOf regularly for writing `description`
> methods:
>
>     var description: String {
>         return "<\(self.dynamicType): \(unsafeAddressOf(self))>{ more info
> here... }"
>     }
>
> I guess this would be covered by some generalized solution for format
> specifiers in string interpolations, but I gather that won't happen for
> quite a while...

If we remove unsafeAddressOf, we have no way to get the address of an
immutable variable.  A mutable variable can be passed inout to a
function taking an UnsafePointer, but you can't add & to an immutable
binding.  

That's a loss I'm willing to take.  I just wanted to point out exactly
what we will have no way to accomplish if we remove unsafeAddressOf.

-- 
Dave



More information about the swift-evolution mailing list