<div dir="ltr">This does not seem to be the case…<br><br><span style="font-family:monospace,monospace"> var buffers:(VBO:GL.UInt, EBO:GL.UInt) = (0, 0)<br> glGenBuffers(n: 2, buffers: &buffers.VBO)<br> print(buffers)<br> // > (VBO: 4, EBO: 0)<br><br> var buffers:(VBO:GL.UInt, EBO:GL.UInt) = (0, 0)<br> glGenBuffers(n: 1, buffers: &buffers.VBO)<br> glGenBuffers(n: 1, buffers: &buffers.EBO)<br> print(buffers)<br> // > (VBO: 4, EBO: 5)<br></span></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jul 20, 2017 at 1:18 PM, Johannes Weiß <span dir="ltr"><<a href="mailto:johannesweiss@apple.com" target="_blank">johannesweiss@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<span class=""><br>
> On 20 Jul 2017, at 5:41 pm, Taylor Swift <<a href="mailto:kelvin13ma@gmail.com">kelvin13ma@gmail.com</a>> wrote:<br>
><br>
> Does addressof count as legally observing it?<br>
><br>
> var buffers:(GL.UInt, GL.UInt) = (0, 0)<br>
> glGenBuffers(n: 2, buffers: &buffers.0)<br>
><br>
> Also, I assume Swift performs a swizzle if the tuple is defined in a separate module from where the pointer to it is constructed?<br>
<br>
</span>yes, that's legal assuming the called function doesn't store the pointer and read/write it later.<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
><br>
> On Thu, Jul 20, 2017 at 4:59 AM, Johannes Weiß <<a href="mailto:johannesweiss@apple.com">johannesweiss@apple.com</a>> wrote:<br>
> When you can (legally) observe it, tuples in Swift have guaranteed standard C-style layout.<br>
><br>
> John McCall confirms this here: <a href="https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20170424/004481.html" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>pipermail/swift-dev/Week-of-<wbr>Mon-20170424/004481.html</a><br>
><br>
> > On 20 Jul 2017, at 4:33 am, Taylor Swift via swift-users <<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>> wrote:<br>
> ><br>
> > Many APIs like OpenGL take arrays where the atomic unit is multiple elements long. For example, a buffer of coordinates laid out like<br>
> ><br>
> > :[Float] = [ x1, y1, z1, x2, y2, z2, ... , xn, yn, zn ]<br>
> ><br>
> > I want to be able to define in Swift (i.e., without creating and importing a Objective C module) a struct that preserves the layout, so that I can do withMemoryRebound(to:capacity:<wbr>_) or something similar and treat the buffer as<br>
> ><br>
> > struct Point<br>
> > {<br>
> > let x:Float,<br>
> > y:Float,<br>
> > z:Float<br>
> > }<br>
> ><br>
> > :[Point] = [ point1, point2, ... , pointn ]<br>
> ><br>
> > The memory layout of the struct isn’t guaranteed, but will the layout be guaranteed to be in declaration order if I use a tuple inside the struct instead?<br>
> ><br>
> > struct Point<br>
> > {<br>
> > let _point:(x:Float, y:Float, z:Float)<br>
> ><br>
> > var x:Float<br>
> > {<br>
> > return self._point.x<br>
> > }<br>
> ><br>
> > var y:Float<br>
> > {<br>
> > return self._point.y<br>
> > }<br>
> ><br>
> > var z:Float<br>
> > {<br>
> > return self._point.z<br>
> > }<br>
> > }<br>
> ><br>
> > This is an ugly workaround, but I can’t really think of any alternatives that don’t involve “import something from Objective C”. I am aware that the implementation of structs currently lays them out in declaration order, but I’m looking for something that’s actually defined in the language.<br>
> ><br>
> ><br>
> > ______________________________<wbr>_________________<br>
> > swift-users mailing list<br>
> > <a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
> > <a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br>
><br>
><br>
<br>
</div></div></blockquote></div><br></div>