<div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote">On Sat, Jul 8, 2017 at 6:28 PM, Chris Lattner via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word">Hi Susan,<div><br></div><div>Swift does not currently specify a layout for Swift structs.  You shouldn’t be using them for memory mapped i/o or writing to a file, because their layout can change.  When ABI stability for fragile structs lands, you will be able to count on it, but until then something like this is probably a bad idea.</div><div><br></div><div>-Chris</div></div></blockquote></div><br></div><div class="gmail_extra">Does this imply that you should never use Swift structs to eg interact with Metal?</div><div class="gmail_extra"><br></div><div class="gmail_extra">This seems to be a very common practice. Here is a typical example (from a Metal tutorial at <a href="http://raywenderlich.com">raywenderlich.com</a>):</div><div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_extra">struct Vertex {</div><div class="gmail_extra">  var x,y,z: Float     // position data</div><div class="gmail_extra">  var r,g,b,a: Float   // color data</div><div class="gmail_extra"><br></div><div class="gmail_extra">  func floatBuffer() -&gt; [Float] {</div><div class="gmail_extra">    return [x,y,z,r,g,b,a]</div><div class="gmail_extra">  }</div><div class="gmail_extra">}</div><div class="gmail_extra"><br></div></div><div class="gmail_extra">( <a href="https://www.raywenderlich.com/146416/metal-tutorial-swift-3-part-2-moving-3d">https://www.raywenderlich.com/146416/metal-tutorial-swift-3-part-2-moving-3d</a> )</div><div class="gmail_extra"><br></div><div class="gmail_extra">Also, does it imply that we cannot use structs (of only primitive types) like:</div><div class="gmail_extra"><br></div><div class="gmail_extra">struct RgbaFloatsLinearGamma {</div><div class="gmail_extra">    var r, g, b, a: Float</div><div class="gmail_extra">    …</div><div class="gmail_extra">}</div><div class="gmail_extra">struct BgraBytesSrgbGamma {</div><div class="gmail_extra">    var b, g, r, a: UInt8</div><div class="gmail_extra">}</div><div class="gmail_extra"><br></div><div class="gmail_extra">for manipulating raster image data?</div><div class="gmail_extra"><br></div><div class="gmail_extra">I vaguely remember a swift evo discussion where it was concluded that such usage was considered OK provided the stored properties of the structs was only primitive types, but I can&#39;t find it now.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Perhaps it could be considered OK at least when the intended platforms are known to be only iOS devices?</div><div class="gmail_extra"><br></div><div class="gmail_extra">/Jens</div><div class="gmail_extra"><br></div></div>