<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">As far as I know, the only guarantee is made for structures imported from C. From <a href="https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20160516/001968.html" class="">https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20160516/001968.html</a> :<div class=""><br class=""></div><div class=""> Swift structs have unspecified layout. If you depend on a specific layout, you should define the struct in C and import it into Swift for now.</div><br class="Apple-interchange-newline">and from <a href="https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20160516/001980.html" class="">https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20160516/001980.html</a> :<div class=""><br class=""></div><div class=""> That's not necessary. You can leave the struct defined in C and import it into Swift. Swift will respect C's layout.<br class=""><br class="Apple-interchange-newline">Regards, Martin</div><div class=""><br class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 28. Apr 2017, at 13:03, Johannes Weiss via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Hi swift-users,<br class=""><br class="">(sorry for the cross post to swift-dev, but wasn't sure where it belongs)<br class=""><br class="">I tried to find guarantees about the memory layout Swift tuples but couldn't find anything. The reason I ask is because I'd like to use them as fixed sized (stack allocated) arrays. I'm pretty sure they're actually not guaranteed to be stack allocated but highly likely I assume :).<br class=""><br class="">Am I correct in assuming that<br class=""><br class=""> let swift_events: (kevent, kevent) = ...<br class=""><br class="">has the same memory layout as<br class=""><br class=""> struct kevent c_events[2] = ...<br class=""><br class="">? In other words, is this legal:<br class=""><br class=""> var events = (kevent(), kevent())<br class=""> withUnsafeMutableBytes(of: &events) { event_ptr in<br class=""> precondition(MemoryLayout<kevent>.size * 2 == event_ptr.count)<br class=""> if let ptr = event_ptr.baseAddress?.bindMemory(to: kevent.self, capacity: 2) {<br class=""> return kevent(someFileDescriptor, ptr, 2, ptr, 2, nil)<br class=""> }<br class=""> }<br class=""><br class="">I'm assuming yes but I'd like to make sure.<br class=""><br class="">Many thanks,<br class=""> Johannes<br class=""><br class="">_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></div></blockquote></div><br class=""></div></div></body></html>