C/C++?????????????
???????????? ???????[ 2014/5/22 11:28:20 ] ????????C C++ ?????????? net
???????????????????????1?????????S1?????????sizeof????????????????4????????????2????????ж???struct??С???????struct?У?????????.
???????????????μ????????
????· __attribute((aligned (n)))?????????????????????n????????????????????г??????????n????????????????????
????· __attribute__ ((packed))????????????????е??????????????????????????ж???
?????????
????struct S3 { };
????sizeof( S3); // ????1
????“?????”?????????????????С???0??????1?????????“??????”???????α????????????????“?????”????????ε??????????????“?????”?????????洢????????????????????????????????????λ???
??????static?????
struct S4{
char a;
long b;
static long c; //???
};
|
??????????????????????????????sizeof??????з????????С??????????????S4???С?4+4=8??
struct S5{
char c;
int i;
};
struct S6
{
char c1;
S5 s;
char c2
};
|
????S5??????????????int??S6?????????????????S5“???”?????????S6?????????int???????????S6????????????洢????????????4??????????sizeof(S6)????????4??????c1????????0??s????????????s????????壬??????????????????????????????????С?8????????4??c1??s???????3???????????c2??s?????????????c2????????12??????c2???С?13??13??????4????????????β???ò???3?????????????sizeof(S6)????16??
??????
![](/images/ad-banner/ad-banner.png)
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11