内存对齐

时间:2014-06-21 17:33:45   收藏:0   阅读:198

虽然内存对齐是老话题,但还是时常犯错,几下个例子,谨记:

 1 void func10()
 2 {
 3     //要牢记,默认按4字节对齐,其他就很容易想了===============================
 4     union u_my
 5     {
 6         int npara;
 7         char name[6];
 8     };
 9 
10     int sizeunion = sizeof(u_my);  //8
11 
12     struct st_my
13     {
14         int nprice;
15         short spara;
16         u_my  uobj;
17     };
18 
19     int nsize = sizeof(st_my);  //16
20 }

其他规则,参考这个例子就清楚了。

内存对齐,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!