[cxx-abi-dev] Question about tail padding

scott douglass sdouglass at arm.com
Fri Aug 16 14:33:21 UTC 2002


At 02:59 PM 16-08-02 +0100, Jason Merrill wrote:
>On Fri, 16 Aug 2002 14:17:05 +0100, scott douglass <sdouglass at arm.com> wrote:
>> I don't think the implicit copy assignment for B can copy all dsize bytes in this case:
>>
>> struct B {
>>     virtual void f(); // B is non-POD
>>     int bf1:3;
>> };
>>
>> struct D : B {
>>     D();
>>     int bf2:3;
>> };
>>
>> Won't bf1 & bf2 be in the same byte?
>
>Nope, the base gets nvsize(B) bytes of space.

I agree that as we are laying out D and just about to layout bf2 dsize(D) == 5.  What happens next depends on how you interpret this sentence in section 2.4/II/1/a:
>The next available n bits are at offset dsize(C) [i.e. dsize(D) for my example], unless the preceding byte is only partially filled by a bitfield, in which case the bitfield allocation can begin in that byte.

Does this mean to say "only partially filled by a bit-field member of C" or does being partially filled by a (trailing) bitfield of a base class count?

g++ 3.1 seems to think bf1 & bf2 can be in the same byte.  Here's my test program:

#include <stdio.h>

struct B {
  virtual void f() { } // B is not POD
  int b:4;
};

struct D : B {
  int c:4;
  char x,y,z;
};

int main() {
  printf("sizeof(B) == %lu; sizeof(D) == %lu\n", (unsigned long)sizeof(B), (unsigned long)sizeof(D));
  int buffer[] = { 0xabbaabba, 0x067452301, 0xefcdab89 };
// With byte-oriented little endianness this looks like
// either A:  (g++ 3.1 chooses this)
//   baabbaab 01234567 89abcdef
//   vvvvvvvv cbxxyyzz
// or B:
//   baabbaab 01234567 89abcdef
//   vvvvvvvv _b_cxxyy zz
  const D* d = reinterpret_cast<const D *>(buffer);
  printf("buffer->b == 0x%x\n", (unsigned)(d->b));
  printf("buffer->c == 0x%x\n", (unsigned)(d->c));
  printf("buffer->x == 0x%02x\n", (unsigned)(d->x));
  printf("buffer->y == 0x%02x\n", (unsigned)(d->y));
  printf("buffer->z == 0x%02x\n", (unsigned)(d->z));
  return 0;
}

My output (linux-x86):
sizeof(B) == 8; sizeof(D) == 8
buffer->b == 0x1
buffer->c == 0x0
buffer->x == 0x23
buffer->y == 0x45
buffer->z == 0x67




More information about the cxx-abi-dev mailing list