This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RFC: attribute "unpadded"

I want to create a new type attribute "unpadded" that would, on
this code:

 struct S __attribute__((unpadded)) {
   int i;
   char c;

define S to have size 5 and alignment 4 on an ILP32 machine.

The idea is that the normal tail padding of S (the three bytes
after "c" to round it out to a multiple of the alignment) would
be suppressed.  It would be illegal to create arrays of these
types, since the required alignment would not then be provided
to all of the array elements.

The motivation for this comes from work on the C++ ABI, including
the tests for interoperability that we are developing.  The C++
ABI essentially has types like the above, but they are implicit.
Making them explicit gives us a way to express the same thing in C.

This comes up in C++ like so:

 struct A { virtual void f();  char c; };
 struct B : public A { char c2 };

Here, the size of B is 8, not 12, because "c2" is packed into
the tail padding of A.  If A were "unpadded", you could express
this in C as:

 struct A __attribute__((unpadded)) { void *vptr; char c; };
 struct B { struct A __base; char c2; };

If I do not here objections, I will create a patch for this and
check it in shortly.  Rats, we are in Stage 3 -- so I will check
it in after we branch for GCC 3.3.

Mark Mitchell
CodeSourcery, LLC

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]