[TUHS] Any UNIX With No C In Userland?

Warner Losh imp at bsdimp.com
Tue Mar 4 04:31:20 AEST 2025


On Mon, Mar 3, 2025, 11:28 AM Larry McVoy <lm at 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__))

Warner

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.tuhs.org/pipermail/tuhs/attachments/20250303/03e972f9/attachment.htm>


More information about the TUHS mailing list