GCC implementing Struct Packing and Alignment on ARM Cortex-M3
I'm having trouble with I'm having a hard time understanding I'm working with a question with structure packing in my C code when compiling for an ARM Cortex-M3 target using GCC version 10.2... I have defined a struct as follows: ```c typedef struct { char a; int b; short c; } __attribute__((packed)) MyStruct; ``` When I attempt to access the members of this struct, I notice that the offsets are not what I expect; it looks like they are not being packed correctly. To debug this, I printed the offsets using the following code: ```c #include <stdio.h> typedef struct { char a; int b; short c; } __attribute__((packed)) MyStruct; int main() { printf("Offset of a: %zu\n", offsetof(MyStruct, a)); printf("Offset of b: %zu\n", offsetof(MyStruct, b)); printf("Offset of c: %zu\n", offsetof(MyStruct, c)); return 0; } ``` The output shows that the offsets are `0`, `1`, and `3`, which is unexpected since I anticipated the `int` to start at `1` and the `short` to follow without gaps. I have tried compiling with different optimization flags like `-O0` and `-O2`, but the scenario continues. Additionally, I used `#pragma pack` to specify alignment, but it didn't change the behavior. Is there something I might be missing regarding GCC's handling of packed structs on ARM? Any advice on how to resolve this or confirm the behavior would be greatly appreciated. For context: I'm using C on Windows. I'd really appreciate any guidance on this. For reference, this is a production desktop app. Any feedback is welcome! My team is using C for this web app. I'd love to hear your thoughts on this. I'm developing on Debian with C. Any ideas how to fix this?