struct calcsize discrepency?

Chris Angelico rosuav at gmail.com
Mon Dec 5 03:09:13 EST 2011


On Mon, Dec 5, 2011 at 6:42 PM, Mark Dickinson <dickinsm at gmail.com> wrote:
> 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.

May be, yes, but since calcsize() is returning 12 when the elements
are put in the other order, it would seem to be not counting such
padding. The way I look at it, padding is always used to place the
beginning of something; in an array, it places the beginning of the
second element on a convenient boundary, rather than filling out the
first element to that boundary.

I tried a similar thing with a couple of C compilers, and both of them
gave the same sizeof() value for both orderings, which would imply
that they _do_ include such padding in the structure's end. My
statement that the padding was removed was based solely on
calcsize()'s different result.

ChrisA



More information about the Python-list mailing list