digitalmars.D.learn - need help to redefine packed c struct in d
```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?
Sep 28 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
Sep 28 2024
On Saturday, 28 September 2024 at 08:35:39 UTC, Johan wrote:On Saturday, 28 September 2024 at 07:54:40 UTC, Dakota wrote:thanks, it work.```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
Sep 28 2024








Dakota <dakota gmail.com>