struct calcsize discrepency?

Mark Dickinson dickinsm at gmail.com
Mon Dec 5 02:42:22 EST 2011


On Dec 4, 3:17 pm, Chris Angelico <ros... at gmail.com> wrote:
> On Mon, Dec 5, 2011 at 1:51 AM, Dave Angel <d... at davea.name> wrote:
> > In C, the padding to the largest alignment occurs at the
> > end of a structure as well as between items.  Otherwise, an array of the
> > struct would not be safely aligned.  if you have an 8byte item followed by a
> > 4 byte item, the total size is 16.
>
> That's padding of the array, not of the structure.

That's a strange way to think of it, especially since the padding also
happens for a single struct object when there's no array present.  I
find it cleaner to think of C as having no padding in arrays, but
padding at the end of a struct.  See C99 6.7.2.1p15: 'There may be
unnamed padding at the end of a structure or union.'  There's no
mention in the standard of padding for arrays.

--
Mark



More information about the Python-list mailing list