possible structure layout bug

Jie Zhang zhangjie@magima.com.cn
Thu Jun 10 09:41:00 GMT 2004


Stephen Kennedy wrote:
> 
> %g++-3.4  layoutbug.cpp && a.out
> __m128 size 16, align 16
> Quad   size 16, align 16
> Base1 32 Derived1 48 Offset 32 <- offset follows sizeof(base)
> Base2 32 Derived2 32 Offset 20 <- offset of derived member is inside
> Base3 64 Derived3 80 Offset 64 <- sizeof(base class)
> 

gcc-3.5.0-20040606 gives different result, which seems consistent. 
However, IMHO it is also wrong:

__m128 size 16, align 16
Quad   size 16, align 16
Base1 32 Derived1 48 Offset 32
Base2 32 Derived2 48 Offset 32
Base3 64 Derived3 80 Offset 64

According to the 386 ABI and C++ ABI used in gcc, I expect the result be

__m128 size 16, align 16
Quad   size 16, align 4
Base1 20 Derived1 24 Offset 20
Base2 32 Derived2 48 Offset 32
Base3 64 Derived3 80 Offset 64

Why does gcc set the alignment of Quad to 16 instead of 4?

-- 
Jie





More information about the Gcc mailing list