[TUHS] Any UNIX With No C In Userland?

Warner Losh imp at bsdimp.com
Tue Mar 4 05:45:50 AEST 2025


On Mon, Mar 3, 2025 at 11:45 AM Steffen Nurpmeso <steffen at sdaoden.eu> wrote:

> Warner Losh wrote in
>  <CANCZdfrb7FLL_zhDq5E65kAzMsJ8HHBYJbcnWn+bhkAPUySKwg at mail.gmail.com>:
>  |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__))
>
> __attribute__((packed, aligned(1)))
>
> I have forgotten why both.
>

packed (or __packed__) says no space between items.

aligned(1) means that the structure can start at any address.

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


More information about the TUHS mailing list