Re: struct calcsize discrepency?



On Dec 4, 3:17 pm, Chris Angelico <ros...@xxxxxxxxx> wrote:
On Mon, Dec 5, 2011 at 1:51 AM, Dave Angel <d...@xxxxxxxxxx> 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
.