why padding is not happening in this case?

前端 未结 4 1660
半阙折子戏
半阙折子戏 2020-12-23 15:14

As per my knowledge, By default 4-byte alignment will be done. say

typedef struct
{
     int data7;  
     unsigned char data8;
     //3 -bytes will be added         


        
4条回答
  •  清酒与你
    2020-12-23 15:42

    None of the fields in your second struct require 4-byte alignment. unsigned char only needs 1-byte alignment. Therefore, there is no need to actually align it to 4 bytes.

    Structs are generally only aligned to the maximum alignment of all the fields.

提交回复
热议问题