???????????洢?????????
?????gongping11 ???????[ 2016/10/31 10:03:18 ] ???????????? ????洢
??????C/C ++?о?????????д洢??????????????????????洢???д洢????????????????????????????????????????????????????洢??С???????о????????????????????????????????????????洢?????????????????????????????????е???????????
??????????????????????????????е??С??char????????1??????int????????4??????double????????8??????short?????2????????????????????仯??????????????????????????????????C??????????????????????????????????????嵽???????洢??????
????????????????C?????洢??????????????????C????????????????????????洢??????????????????????????????????????????????????????????????????????Щ??????????????豸???????????????????????????????????????????
??????32bits?????ж???????????32bits????????????????????????????????????????????ú???????????????????????????????????????????????????????????????????????????????????????????CPU?????????ж????????????????????????4?????????????????????????????Щ?????????????????????????4??bytes????????????????????????????????????????????4??bytes???ɡ?
?????????????????????????????????????洢???????????????
????????????????н??????塣????????????
????1???????????????????????????????????????????????????????????ж?????С???????????????????????ζ?????棬??????????????????????????2??
????2???????е?????????????????????????????洢????????????????????????????????
????3????????д???????????£????????????д???????????????(????????????е????????????)??
????????????????????????????????linux?д?????????4?????????????????е??????????????????4???????????4????????????????д?????????????????????????????????????????????????????????????????????????????????????4???ɡ???????????д????????????С??4????????????????????????
??????????windows?л?????????????????????????ж?????????????????
??????????????Щ??????о????????????????????н??齫???????????????????????????????????????????????????????????????????????????????壬????????????????????????
????????????????????????????
????#include<stdio.h>
????#include<stdlib.h>
????struct aa{
????char a;
????double b;
????short c;
????};
????struct bb
????{
????double a;
????short b;
????char c;
????};
????struct cc
????{
????struct bb s1;
????char s2;
????};
????struct dd
????{
????struct aa s1;
????char s2;
????};
????#pragma pack(1)
????struct ee
????{
????double a;
????short b;
????char c;
????};
????struct ff
????{
????char a;
????double b;
????short c;
????};
????#pragma pack()
????struct gg
????{
????char a;
????};
????struct jj
????{
????char a;
????short b;
????};
????int main()
????{
????printf("double size is %d %d %d
"??sizeof(double)??sizeof(short)??sizeof(char));
????printf("size of s1 = %d
size of s2 = %d
"??sizeof(struct aa)??sizeof(struct bb));
????printf("size of t1 = %d
size of dd = %d
"??sizeof(struct cc)??sizeof(struct dd));
????printf("size of struct ee = %d
size of struct ff = %d
size of struct gg = %d
size of struct jj = %d
"??
????sizeof(struct ee)??sizeof(struct ff)??sizeof(struct gg)??sizeof(struct jj));
????exit(0);
????}
??????linux?μ?????
??????windows?μ?????
??????
???·???
??????????????????
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