What exactly is an 'aligned pointer'?

前端 未结 6 1931
执笔经年
执笔经年 2020-11-29 22:28

Would somebody please tell me what an aligned pointer actually means?

6条回答
  •  孤独总比滥情好
    2020-11-29 22:51

    To add to what unwind is explaining, here is a struct I have recently used in an assignment :

    struct infosale {               
        int   noseq;                
        char  salesman[30];         
        char  product[11];          
        int   count;                
    };                               
    

    You may expect the size of this struct to be (4+30+11+4=) 49 bytes, but it is in fact 52 compared with sizeof. Because noseq is 4 bytes + salesman is 32 bytes (aligned) + product is 12 bytes (aligned) and count is 4 bytes, thus 52 bytes.

提交回复
热议问题