<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Mon, Mar 3, 2025 at 11:45 AM Steffen Nurpmeso <<a href="mailto:steffen@sdaoden.eu">steffen@sdaoden.eu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Warner Losh wrote in<br>
 <<a href="mailto:CANCZdfrb7FLL_zhDq5E65kAzMsJ8HHBYJbcnWn%2BbhkAPUySKwg@mail.gmail.com" target="_blank">CANCZdfrb7FLL_zhDq5E65kAzMsJ8HHBYJbcnWn+bhkAPUySKwg@mail.gmail.com</a>>:<br>
 |On Mon, Mar 3, 2025, 11:28 AM Larry McVoy <<a href="mailto:lm@mcvoy.com" target="_blank">lm@mcvoy.com</a>> wrote:<br>
 |> On Mon, Mar 03, 2025 at 05:55:10PM +0000, segaloco via TUHS wrote:<br>
 |>> Truth be told the subjectivity of implementing struct memory<br>
 |> 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>
 |><br>
 |<br>
 |__attribute__ ((__packed__))<br>
<br>
__attribute__((packed, aligned(1)))<br>
<br>
I have forgotten why both.<br></blockquote><div><br></div><div>packed (or __packed__) says no space between items.</div><div><br></div><div>aligned(1) means that the structure can start at any address.</div><div><br></div><div>Warner</div></div></div>