Struct packing and alignment with mingw

后端 未结 3 1323
别那么骄傲
别那么骄傲 2021-01-12 18:40

I am emulating code from an embedded system (stm32, Keil µVision 5, MDK-ARM) on a PC (mingw32, 32bit arch). The alignment of the ARM compiler does not match my desktop m

3条回答
  •  隐瞒了意图╮
    2021-01-12 19:23

    According to the GCC manual's examples, the attribute should go after the struct's fields, i.e.:

    // PC Code
    typedef struct
    {
        uint8_t var1;
        uint16_t var2;
    } __attribute__((packed, aligned(1))) FILE;
    

    I also dropped the pointless struct tag (_file).

    The above has a sizeof value of 3 when I tested it quickly.

提交回复
热议问题