Boost logo

Boost :

Subject: Re: [boost] bug in type_traits/is_virtual_base_of ??
From: Daniel Larimer (dlarimer_at_[hidden])
Date: 2010-02-11 14:02:14


I think I found the root cause of the "bug", padding of the data structure for 64 bit alignment which is revealed by looking at the sizeof() different structs.

struct A
{
        int x; // 4 bytes
}
struct B
{
        int y; // 4 bytes
}

struct C : A, B
{
        int z; // 12 bytes
}
struct D : A, B
{
        virtual ~D(){} // 8 bytes for virtual table ptr
        int z; // 4 bytes
}

sizeof(C) == 12
sizeof(D) == 24

In other words, the presence of a virtual pointer added 12 bytes instead of 8 bytes which implies the compiler is padding the data structure.

If I change A::x to int64_t then everything works as expected, there is no unaccounted for "padding".

Dan

On Feb 11, 2010, at 12:59 PM, John Maddock wrote:

>> cast the bool to an int, still does not work. It works for most cases, for example this works:
>>
>> struct C : public A, public B
>> {
>> virtual test(); //
>> }
>>
>> struct C : public A, public B
>> {
>> virtual test();
>> float parameter; // DOESN"T WORK ANY MORE
>> };
>>
>
> Which specific compiler version? I need something that I can reproduce here... John.
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk