On 02/11/2024 00:55, Oren Zvi via Gcc wrote: > Hi, > > Was wondering about a curious thing that the compiler does. > For the code > > static void createX() > { > static char xxxx; > static uint8_t y; > > printf("%c %c\r\n", y, xxxx); > } > > I am getting the following lines in the memory map: > > .bss._ZZL7createXvE4xxxx > 0x200024c0 0x1 > .bss._ZZL7createXvE11y > 0x200024c1 0x1 > > If I change y to > static uint8_t y[1]; > > I am getting the following memory map: > .bss._ZZL7createXvE4xxxx > 0x200024c0 0x1 > *fill* 0x200024c1 0x3 > .bss._ZZL7createXvE11y > 0x200024c4 0x1 > > Is this a well known behaviour that GCC will always align the start address > for an array? > > Thanks, > Oren
It's not part of the ABI, but there can be performance benefits from aligning arrays, for example when code is vectorized. It's not possible to easily tell exactly how large the array will be in practice, so even very small ones get aligned. There's no point in doing this for scalar objects as the next location cannot ever contain a related object.