array different w/ and w/o GCC aligned attribute in rpi3?

Is array different w/ and w/o GCC aligned attribute in rpi3?

目前我正在跟踪rpi3邮箱的例子,我发现了一些奇怪的东西。 根据wiki:

The buffer itself is 16-byte aligned as only the upper 28 bits of the address can be passed via the mailbox.

我发现 code 可能与描述有关:

volatile unsigned int  __attribute__((aligned(16))) mbox[36];

我认为作者试图将其与 16 字节对齐,但我将会员地址转储为 C 代码:

#include <stdio.h>
volatile unsigned int  __attribute__((aligned(16))) mbox[36];

int main()
{
    printf("%p\n%p\n%p\n", &mbox[0], &mbox[1], &mbox[2]);

    return 0;
}

输出:

0x601040
0x601044
0x601048

我发现它是 4 字节对齐的。我的问题是这个属性在这里的目的是什么或者它重要吗?

Is array different w/ and w/o GCC aligned attribute in rpi3?

嗯,不,数组本身没有什么不同,只是整个数组的位置受到影响。

如果你想让类似的数组元素对齐,做一个对齐结构的数组。

I found it's 4 bytes aligned

当然,数组的元素是 4 字节对齐的 - 看起来 int 在您的平台上有 4 个字节。

My question is what is the purpose of this attribute in here

使数组 mbox 对齐到 16,而不是它的元素。

did it matter?

是的。