C++11 introduced the alignas
specifier to specify the alignment of a variable, and the alignof
operator to query the default alignment of a type. However, I don't see any way to get the alignment of a specific variable. Let's take the following trivial example:
alignas(16) float* array;
Here is what we can do about it:
alignof(float*)
returns 8, which is obviously not what we want.alignof(array)
returns 16, which is exactly what we want, but that's a compiler extension;alignof
as specified by the standard can't be used on a specific variable.alignof(decltype(array))
returns 8, which was quite expected but not what we want.std::alignment_of
is implemented in terms ofalignof
, so it doesn't help much.
I would like a mechanism to confirm that the specific variable array
is aligned on a 16 byte boundary. Is there anything in the standard to perform such a query?