Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ parent class alignment

Is it possible to specify alignment of parent class? for example something like (which does not compiled):

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

thanks

well, from comments I gather this is no good way to go. I think I will just stick to composition/alignment of private array

like image 465
Anycorn Avatar asked Jun 14 '26 19:06

Anycorn


1 Answers

We don't need to request alignment on the derived class neither we can. The reason why we don't need is that it is enough to request alignment for the derived class, and that requesting alignment to the derived class will result on layout for the base class that depends on the derived.

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


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

Which will be alignment for C?

like image 200
Vicente Botet Escriba Avatar answered Jun 16 '26 11:06

Vicente Botet Escriba



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!