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

前端 未结 9 2088
萌比男神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:21

    5.3.3/2

    When applied to a class, the result [of sizeof] is the number of bytes in an object of that class, including any padding required for placing objects of that type in an array.

    So yes, object size is a multiple of its alignment.

提交回复
热议问题