[swift-users] String init from Int8 tuple?

Martin R martinr448 at gmail.com
Wed Apr 19 03:14:25 CDT 2017

This reminds me of my previous question https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20170220/004841.html <https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20170220/004841.html>

> Is that simplified guaranteed to work? The Swift book says that
> > As an optimization, when the argument is a value stored at a physical address in memory, the same memory location is used both inside and outside the function body.
> but also 
> > Write your code using the model given by copy-in copy-out, without depending on the call-by-reference optimization, so that it behaves correctly with or without the optimization.
> If `tmp.0` is copied to a separate location then `String(cString: &tmp.0)` would not work correctly, or would it?

to which Quinn responded https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20170220/004842.html <https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20170220/004842.html>

> Based on a previous conversation I had with the Swift folks about this, yes.
> However, I don’t work on the compiler so it’s possible I misunderstood.  Perhaps someone from SwiftLand™ will chime in here.

Some authoritative response from SwiftLand™ would be much appreciated.

Regards, Martin

> On 19. Apr 2017, at 09:16, Quinn The Eskimo! via swift-users <swift-users at swift.org> wrote:
> On 19 Apr 2017, at 02:11, Rick Mann via swift-users <swift-users at swift.org> wrote:
>> In my C-interop, I have a need to do this a lot:
> I think you’re working too hard here.  Try this:
> func callbackFailed(info inInfo: lgs_result_info_t) {
>   var m = inInfo.message
>   let message = String(cString: &m.0)
>   debugLog("Failed: \(message)")
> }
> Alas, you still need to do the copy in order to take the address of `m`.
> Share and Enjoy
> --
> Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
> Apple Developer Relations, Developer Technical Support, Core OS/Hardware
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170419/244d9aee/attachment.html>

More information about the swift-users mailing list