??????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?μ?????