calculating the size of structure

前端 未结 3 1025
南方客
南方客 2021-01-26 10:09

I was going through the concept of structure member alignment and structure padding concept when I found that the size of this struct ...

struct nod         


        
3条回答
  •  臣服心动
    2021-01-26 11:03

    Remember theses two rules for padding:

    1. Padding is only inserted when a structure member is followed by a member with a larger alignment requirement or at the end of the structure.
    2. The last member is padded with the number of bytes required so that the total size of the structure should be a multiple of the largest alignment of any structure member.

    Member a in second structure is not followed by any member or member with larger alignment and it is also the largest alignment member which means--No Padding.

    Read this answer for more detailed explanation.

提交回复
热议问题