一行代码值一千字 :) 这是我的问题:
/* Platform specific 16-byte alignment macro switch.
On Visual C++ it would substitute __declspec(align(16)).
On GCC it substitutes __attribute__((aligned (16))).
*/
#define ALIGN_16 ...
struct ALIGN_16 A {...};
A* ptr = new A;
A* ptr2 = new A[20];
assert(size_t(ptr) % 16 == 0);
for (int i=0; i<20; ++i)
assert(size_t(ptr2+i) % 16 == 0);
assert(sizeof(A) % 16 == 0);
我可以期望所有断言都在支持 SSE 的平台上传递吗?谢谢你。
编辑。部分回答。我用 VS2008、GCC 和 ICC 做了一些测试。MS 编译器确实对齐了ptr和ptr2,但是 GCC 和 ICC 未能对齐ptr2。