Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • So you mean sizeof calculates the padding between the vars, but not the alignment bytes at the end/beginning of the struct? Commented Mar 25, 2011 at 17:19
  • yes, I suppose that it has to return me alignment bytes at the end/beginning Commented Mar 25, 2011 at 17:21
  • @Ivan Your first struct is aligned. The alignment there is on a 2-byte boundary, since that's the size of the largest element of the struct. The second struct is aligned on a 4-byte boundary (because of the int). Neither needs any padding at the beginning or end. Commented Mar 25, 2011 at 17:23
  • @Hossein sizeof includes both the padding inside the struct and at the end. The size myStruct is 6 bytes since there are no padding at the end of the struct. The reason for this is that you don't need it since it only contains members that require 2-byte alignment. Commented Mar 25, 2011 at 17:27