Re: struct calcsize discrepency?
- From: Mark Dickinson <dickinsm@xxxxxxxxx>
- Date: Sun, 4 Dec 2011 23:42:22 -0800 (PST)
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
.
- Follow-Ups:
- Re: struct calcsize discrepency?
- From: Chris Angelico
- Re: struct calcsize discrepency?
- References:
- struct calcsize discrepency?
- From: Glen Rice
- Re: struct calcsize discrepency?
- From: Chris Angelico
- struct calcsize discrepency?
- Prev by Date: Re: order independent hash?
- Next by Date: Re: class print method...
- Previous by thread: Re: struct calcsize discrepency?
- Next by thread: Re: struct calcsize discrepency?
- Index(es):
Relevant Pages
|