__attribute__机制实际上是 GCC 的一种编译器命令,用来指示编译器执行实现某些高级操作。
__attribute__可以设置函数属性(Function Attribute)、变量属性(Variable Attribute)和类型属性(Type Attribute)。
LLVM也借用了GCC的__attribute__,并进行了扩展。
__attribute__ ((attribute-list))
指定对象的对齐格式(以字节为单位),如:
struct S {
short b[3];
} __attribute__ ((aligned (8)));
typedef int int32_t __attribute__ ((aligned (8)));
该声明将强制编译器确保(尽它所能)变量类 型为struct S 或者int32_t 的变量在分配空间时采用 8 字节对齐方式。
需要注意的是,attribute 属性的效力与你的连接器也有关,如果你的连接器最大只支持16 字节对齐,那么你此时定义32 字节对齐也是无济于事的。