Thread overview
need help to redefine packed c struct in d
Sep 28
Dakota
Sep 28
Johan
Sep 28
Dakota
September 28
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?

September 28

On Saturday, 28 September 2024 at 07:54:40 UTC, Dakota wrote:

>
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

September 28

On Saturday, 28 September 2024 at 08:35:39 UTC, Johan wrote:

>

On Saturday, 28 September 2024 at 07:54:40 UTC, Dakota wrote:

>
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

thanks, it work.