<div dir="auto"><div><br><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Mon, Mar 3, 2025, 11:28 AM Larry McVoy <<a href="mailto:lm@mcvoy.com">lm@mcvoy.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Mon, Mar 03, 2025 at 05:55:10PM +0000, segaloco via TUHS wrote:<br>
> Truth be told the subjectivity of implementing struct memory characteristics has<br>
> bewildered me more rather than less as time goes on. <br>
<br>
Alignment is your answer. Understand that and the confusion goes away:<br>
<br>
slovax ~/tmp cat pack.c<br>
#include <stdio.h><br>
<br>
struct {<br>
char a;<br>
int b;<br>
} foo;<br>
<br>
int<br>
main(void)<br>
{<br>
printf("%lu\n", sizeof(foo));<br>
return (0);<br>
}<br>
<br>
slovax ~/tmp cc pack.c<br>
slovax ~/tmp a.out<br>
8<br>
<br>
<br>
Even x86, it would appear, wants to do aligned loads. I'm a little<br>
surprised by that though maybe I shouldn't be as there is a RISC<br>
implemented by the microcode under the x86 CPU.<br>
<br>
Does anyone know if gcc has an option to ignore alignment and pack the<br>
structs?<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">__attribute__ ((__packed__))</div><div dir="auto"><br></div><div dir="auto">Warner</div><div dir="auto"><div class="gmail_quote gmail_quote_container"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></div>