C/C++?????????????
???????????? ???????[ 2014/5/22 11:28:20 ] ????????C C++ ?????????? net
???????????????????????????????????????????????????.?????????????????????????????????(??????????????С)????????????(?????????8???)?н?С?????????.?????????????????ù??????ж???????????????????????????.
????????(struct)??sizeof????????????????и?????????????????????????洢????????????????????漲???????????.
struct
{
char a;
short b;
char c;
}S1;
struct
{
char a;
char b;
short c;
}S2;
|
????????ó??????ó?sizeof(S1)=6 ?? sizeof(S2)=4
??????????????????????????????????????????д?????????????????????????????????????????????????????????????????????????????????????????
?????????????
????????????????????????????????
????1) ?????????????????????????????????С????????
????2) ???????????????????????????????offset???????????????????????????????С??????????????????????????????????????????internal adding????
????3) ????????С?????????????????С???????????????????????????????????????????????trailing padding????
????????????????????????????????int a[10]???????10?????α???????????
???????????????????????????????struct???????.
????????struct S1?? ????short?????????????????(2)?? ????洢λ????????????????offset???????С(short?2?????)???????????????????a?????????????????????????(3)????? ??????????С?short??С??????????????????c??????????????
????????struct S2?? ?????????????????????????????????洢???????????????
??????????????????????е?short?????int(?4?????)?? ????????????? ????ó?sizeof(S1)=12?? sizeof(S2)=8
????????????????????????ó???????????S1????a???????3????????c???????3?????????????12??????S2????a??b???洢???????????????????????????8??????
????????????Щ????????????????????????????? #pragma pack ??
#pragma pack(push) //??????
#pragma pack(1)// ????1??????
struct
{
char a;
short b;
char c;
}S1;
#pragma pack(pop) // ??????????
|
??????
???·???
??????????????????
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