need help to redefine packed c struct in d

Johan j at j.nl
Sat Sep 28 08:35:39 UTC 2024


On Saturday, 28 September 2024 at 07:54:40 UTC, Dakota wrote:
> ```c
> struct __attribute__((packed)) type1 {
>     uint32_t        u32;
>     uint8_t         u8;
>     uint16_t        u16a;
>     uint16_t        u16b;
>     uint8_t         u8a;
>     uint8_t         arr[14];
> };
>
> ```
>
> the struct size in C is 24:
>
> I try `pragma(packed)` and `align(1):`, the d size always is 25.
>
> how to fix this?

Put the `align(1):` inside the struct definition.
https://d.godbolt.org/z/qqsK1ro9v

-Johan


More information about the Digitalmars-d-learn mailing list