Alignment of Member Array in Class not Working

273 Views Asked by At

I use the following to 16-byte align a 4 element float array in a class

class Foo
{
    // ... some code

    private:
    alignas(16) float array[4];
};

The variable is not aligned. Why is that? My assumption would be that the alignment depends on the alignment of the instance of Foo since the internal offset of member variables is static and not adjusted on runtime. Is that correct or am I missing something? Thus one thing to fix it would be to align Foo with something >=16 so that the internal offsets are fixed?

0

There are 0 best solutions below