奇怪了,sizeof与结构的问题
定义了一个结构TMsg_Bind,里面仅仅包含两个结构TMsg_Head,TMsg_Body,结果发现使用
sizeof计算Tmsg_Bind类型的变量BindData的大小时候,不是他两个结构大小的和,请问为什么??
var
BindData:TMsg_Bind;
begin
ShowMessage(IntToStr(sizeof(BindData.MsgHead))); //20
ShowMessage(IntToStr(sizeof(BindData.MsgBody))); //41
ShowMessage(IntToStr(sizeof(BindData))); //64 ???
各结构定义如下:
TMsgHead = record //所有消息体的消息头 20字节
iMsgLen:Longint;
iMsgID:Longint;
sMsgSerial:Array[0..11] of char;
end;
TMsgBody_Bind = record //bind消息体 41字节
iLoginType:Byte;
sLoginUser:Array[0..15] of char;
sLoginPwd:Array[0..15] of char;
sReserve:Array[0..7] of char;
end;
TMsg_Bind=record
MsgHead:TMsgHead;
MsgBody:TMsgBody_Bind;
end;