For this code:
struct S { unsigned char ch[2]; };
int main(void)
{
_Static_assert( sizeof(struct S) == 2, "size was not 2");
}
using GCC (various versions) for ARM with the ABI apcs-gnu
(aka. OABI, or EABI version 0), I get the assertion fails. It turns out the size of the struct is 4
.
I can work around this by using __attribute__((packed))
; but my questions are:
- What is the rationale for making this struct size
4
? - Is there any documentation specifying the layout of structs in this ABI?
On the ARM website I found documentation for aapcs
(EABI version 5) which does specify this struct as having a size of 2; but I could not find anything about apcs-gnu
.