<div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div><div>So the current algorithm  in #defineFields: and compileFields: is producing compact structures layout with all fields aligned on 1 byte.<br></div><br></div>It does not correspond to any platform behavior except when using special pragmas or compiler options.<br><br></div>The current workaround is to force a length in 3rd column of spec.<br><a href="https://stackoverflow.com/questions/49782651/how-one-aligns-structure-fields-in-squeak-ffi/49782754#49782754">https://stackoverflow.com/questions/49782651/how-one-aligns-structure-fields-in-squeak-ffi/49782754#49782754</a><br></div>But it's brainfuck:<br>- it depends both on the fields preceding and the fields following<br></div><div>- it becomes very hard to support both 32+64 bits<br></div><div><br></div>#(<br>    (x 'char' 2)<br>    (y 'short')<br> )<br>#(<br>    (x 'char' 4) "depends on the field following"<br>    (y 'long')<br> )<br>#(<br>    (w 'char' 1)<br>    (x 'char' 3) "but also on the field preceding"<br>    (y 'long')<br> )<br><br></div>I'd like to make our default behavior match that of the current platform<br></div>- atomic fields of size 1,2,4,8 bytes have alignment = size<br></div><div>- pointers also have alignment = pointer size (4 or 8).<br></div>- nested structures have alignment = max of alignment of their fields<br><br></div>Then we can support exotic alignment with a 4th column in spec:<br><br></div>#( (x 'char' -1 1) (y 'short' -1 1) ) "compact"<br><br></div>The 3rd column -1 or nil would mean<br>"use the default size rather than force a user defined one"<br><br></div>Other suggestions?<br></div>