跨平台属性对齐

attribute aligned crossplatform

本文关键字:对齐 属性 跨平台      更新时间:2023-10-16

是GCC的

union uint128_t {
    uint64_t q[2];
    uint64_t w[8];
    char b[16];
} __attribute__((aligned (16)));

与(跨平台(相同:

union alignas(16) uint128_t {
    uint64_t q[2];
    uint64_t w[8];
    char b[16];
};

是的。 请参阅__attribute__((aligned))alignas

如果你问"为什么<某些图书馆>使用__attribute__而不是alignas? 我怀疑答案是"因为alignas相对较新,但__attribute__支持的时间要长得多。