Is the size of a struct required to be an exact multiple of the alignment of that struct?

前端 未结 9 2084
萌比男神i
萌比男神i 2020-11-28 13:00

Once again, I\'m questioning a longstanding belief.

Until today, I believed that the alignment of the following struct would normally be 4 and the size would normall

9条回答
  •  野性不改
    2020-11-28 13:17

    The standard says (section [dcl.array]:

    An object of array type contains a contiguously allocated non-empty set of N subobjects of type T.

    Therefore there is no padding between array elements.

    Padding inside structures is not required by the standard, but the standard doesn't permit any other way of aligning array elements.

提交回复
热议问题