Memory alignment for arrays in GCC for ARM

Oren Zvi Oren.Zvi@breville.com
Sat Nov 2 00:55:57 GMT 2024


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


More information about the Gcc mailing list