C ++ parent class alignment

Can parental class alignment be specified? for example, something like (which is not compiled):

template<size_t n> class Vector : public boost::array<double,n> __attribute__ ((aligned(16))) { 

thanks

Well, from the comments I am collecting, this is not a good way to go. I think that I will just stick to private array composition / alignment

+3
source share
2 answers

We do not need to request alignment with the derived class, we cannot. The reason why we don’t need it is that it is enough to request alignment for the derived class and the request for alignment of the derived class will lead to the layout of the base class, which depends on the received one.

 class A : public C __attribute__ ((aligned(16))) { class B : public C __attribute__ ((aligned(8))) { 

What will be the alignment for C?

+5
source

GCC ensures that the first base class is at a zero offset in the layout of the derived class. Therefore, in this case, it is enough to align the derived object.

I cannot find a good link at the moment, but see here in the -wABI section where they describe an exception for an undefined rule: if the base is empty, it may not be zero.

I assume that there will be another exception if the first base does not have a vtable, but the derived object has one. array falling into this category, I would look. Of course, the standard leaves the layout unspecified: Β§10 / 3.

+2
source

Source: https://habr.com/ru/post/1488678/


All Articles