声明指向对齐类型的指针的语法是什么?指向对齐的对象数组的指针和指向对象数组的指针之间是否存在歧义,每个对象都是对齐的?
例如,如果没有foo
或using
,我将如何实施typedef
?
template <class T, int N>
using Aligned alignas(N) = T;
void foo(Aligned<float, 64>* vals, int size)
{
for (int i = 0; i != size; ++i)
vals[i] *= 2.0f;
}
// the above seems a bit ambiguous -- maybe it could be a pointer to
// floats that are each 64 byte aligned? -- but it gives the same
// code as the following so it seems to be doing the right thing
void bar(float* vals, int size)
{
vals = (float*)__builtin_assume_aligned(vals, 64);
for (int i = 0; i != size; ++i)
vals[i] *= 2.0f;
}