views:

78

answers:

2

hello.

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

+2  A: 

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?

Vicente Botet Escriba
I see your point, will wait to see how other weigh in
aaa
+2  A: 

GCC guarantees that the first base class is at offset zero within the derived class layout. Therefore it's sufficient in this case to align the derived object.

I can't find a good reference at the moment but see here under -wABI, where they describe an exception to the unstated rule: if the base is empty, it may not be at offset zero.

I suppose there would be another exception if the first base lacks a vtable but the derived object has one. array falling into that category, I'd watch out. Of course, the standard leaves layout unspecified: §10/3.

Potatoswatter