7 years, 12 months ago.

array size is padded to 8 byte?!?!?

Something weird I stumbled upon today:

typedef struct { uint8_t A[7]; uint32_t B; } strct;

Expecting sizeof(strct) to be 7+4 = 11 bytes, but instead I get 12. Looking at the memory layout, it looks like a byte is padded between A and B values.

Explanation ?

1 Answer

7 years, 12 months ago.

This is normal for C compilers, also some CPU require int on sizeof(int) boundaries. For several compilers there are pragma statements change this. Look for "#pragma pack" of the ARM compiler.

Accepted Answer