[cxx-abi-dev] Question about tail padding
Nathan Sidwell
nathan at codesourcery.com
Thu Aug 22 20:02:08 UTC 2002
"Nelson, Clark" wrote:
> The problem Scott pointed out was about packing bit-fields from derived and
> base classes into the same byte. Intel's compiler doesn't do that. We
> instead wind up with the bit-field in the derived class in a poorly-aligned
> container, which is a smaller performance problem.
ah, what you're saying is that A::a is bits 0& 1 of byte 4,
and B::b is bits 0 & 1 of byte 5.
So, the intel compiler doesn't consider that an int bitfield
reserves 4 bytes of an allocation unit, but takes the unused
bytes of that as tail padding?
I've just checked g++ with the attached, it shows that B::b is
allocated in bits 2 & 3 of byte 4.
nathan
--
Dr Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
'But that's a lie.' - 'Yes it is. What's your point?'
nathan at codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan at acm.org
-------------- next part --------------
#include <stdio.h>
#include <string.h>
struct A
{
virtual ~A (){}
int a : 2;
};
struct B : A
{
int b : 2;
};
struct C
{
A a;
int c : 2;
};
int main ()
{
B b;
char *ptr = (char *)(void *)&b;
printf ("A %u, B %u C %u\n", sizeof (A), sizeof (B), sizeof (C));
memset (ptr, 0, sizeof (B));
b.b = 3;
printf ("byte 4 %x, byte 5 %x\n", ptr[4], ptr[5]);
}
More information about the cxx-abi-dev
mailing list