<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta content="text/html; charset=utf-8">
</head>
<body>
<div id="compose-container" itemscope="" itemtype="https://schema.org/EmailMessage" style="direction:ltr">
<span itemprop="creator" itemscope="" itemtype="https://schema.org/Organization"><span itemprop="name"></span></span>
<div>
<div style="direction:ltr">Which backend?</div>
<div><br>
</div>
<div style="direction:ltr">In any case I would recommend avoiding passing/returning structs/records by value across languages or even "major" compilers.</div>
<div><br>
</div>
<div style="direction:ltr">This is a somewhat unusual "corner" in some ABIs and there are often accidental mismatches.</div>
<div><br>
</div>
<div style="direction:ltr">I know the integrated NT386 backend has a problem and we workaround it.</div>
<div><br>
</div>
<div style="direction:ltr">There is approx. one Win32 API affected. We wrap it with a C wrapper that uses explicit record address instead of value.</div>
<div><br>
</div>
<div style="direction:ltr">Basically this is an area that 1. Has multiple obvious reasonable approaches and no clear tie breaker if you are the designer. 2. Is sometimes tweaked. Leaving intended clones not always matching.</div>
<div><br>
</div>
<div style="direction:ltr">For example I believe NT/amd64...I looked it up...structs of size 1, 2, 4, 8 are passed in registers (presumably only if in first 4 parameters). I didn't see how returned. Any other</div>
<div style="direction:ltr">in-between or larger size is passed differently. C does not allow zero-sized structs, I'm not sure of others.</div>
<div><br>
</div>
<div style="direction:ltr">This is something sort of fixed by generating C, but I've seen C compilers mismatch too (citation needed).</div>
<div><br>
</div>
<div style="direction:ltr">What is actual scenario?</div>
<div><br>
</div>
<div class="acompli_signature">- Jay</div>
</div>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> M3devel <m3devel-bounces@elegosoft.com> on behalf of Peter McKinna <peter.mckinna@gmail.com><br>
<b>Sent:</b> Sunday, June 25, 2017 11:21:51 PM<br>
<b>To:</b> m3devel<br>
<b>Subject:</b> [M3devel] small structs</font>
<div> </div>
</div>
<div>
<div dir="ltr">Hey,
<div>  I have a problem passing small structs by value to an external C function. If the size of the struct/record is less than 16 bytes there seems to be an ABI mismatch, at least on x86_64 not sure of other targets. If it's larger than 16 bytes the value
 is passed on the stack as usual and works fine otherwise it looks as if the fields of the struct are extracted and passed in registers.</div>
<div><br>
</div>
<div>  Any thoughts?</div>
<div><br>
</div>
<div>Regards Peter</div>
<div><br>
</div>
</div>
</div>
</body>
</html>