Warner Losh wrote in
<CANCZdfrb7FLL_zhDq5E65kAzMsJ8HHBYJbcnWn+bhkAPUySKwg(a)mail.gmail.com>:
|On Mon, Mar 3, 2025, 11:28 AM Larry McVoy <lm(a)mcvoy.com> wrote:
|> On Mon, Mar 03, 2025 at 05:55:10PM +0000, segaloco via TUHS wrote:
|>> Truth be told the subjectivity of implementing struct memory
|> characteristics has
|>> bewildered me more rather than less as time goes on.
|>
|> Alignment is your answer. Understand that and the confusion goes away:
|>
|> slovax ~/tmp cat pack.c
|> #include <stdio.h>
|>
|> struct {
|> char a;
|> int b;
|>} foo;
|>
|> int
|> main(void)
|> {
|> printf("%lu\n", sizeof(foo));
|> return (0);
|>}
|>
|> slovax ~/tmp cc pack.c
|> slovax ~/tmp a.out
|> 8
|>
|>
|> Even x86, it would appear, wants to do aligned loads. I'm a little
|> surprised by that though maybe I shouldn't be as there is a RISC
|> implemented by the microcode under the x86 CPU.
|>
|> Does anyone know if gcc has an option to ignore alignment and pack the
|> structs?
|>
|
|__attribute__ ((__packed__))
__attribute__((packed, aligned(1)))
I have forgotten why both.
--steffen
|
|Der Kragenbaer, The moon bear,
|der holt sich munter he cheerfully and one by one
|einen nach dem anderen runter wa.ks himself off
|(By Robert Gernhardt)