我得到了这个 union ,我正试图使用 gcc 4.8 将其对齐到 16 字节边界。
typedef union {
unsigned long long int ud[(1<<6)/8];
long long int d[(1<<6)/8];
unsigned int uw[(1<<6)/4];
int w[(1<<6)/4];
short uh[(1<<6)/2];
unsigned short int h[(1<<6)/2];
unsigned char ub[(1<<6)/1];
char b[(1<<6)/1];
} vector_t;
我试过了
vector_t __attribute__ ((aligned(16))) t;
但它不起作用。堆栈中变量 t 的地址未按 16 字节对齐。
我能够在 VS 10 中使用 __declspec align(16) 对齐它。请告诉我在 gcc 中执行此操作的方法是什么。
最佳答案
关键字__attribute__
允许您在定义struct
和union
类型时指定这些类型的特殊属性.你需要做的
typedef union __attribute__ ((aligned(16))) {
unsigned long long int ud[(1<<6)/8];
long long int d[(1<<6)/8];
unsigned int uw[(1<<6)/4];
int w[(1<<6)/4];
short uh[(1<<6)/2];
unsigned short int h[(1<<6)/2];
unsigned char ub[(1<<6)/1];
char b[(1<<6)/1];
} vector_t;
关于c - 在 x86 中将 union 对齐到 16 字节边界。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24924154/