packed属性(GCC)

packed属性(GCC)

Content #

packed属性可以使变量或者结构体成员使用最小的对齐方式,对变量是以字节对齐,对域是以位对齐。

struct test
{
    char a;
    int x[2] __attribute__ ((packed));
};

x成员使用了packed属性,它会存储在变量a后面,所以这个结构体一共占用9字节。

From #

奔跑吧Linux内核——入门篇