郁闷,大家帮我看看这个数据结构的大小到底应该是多少?(50分)

  • 主题发起人 主题发起人 seagod007
  • 开始时间 开始时间
S

seagod007

Unregistered / Unconfirmed
GUEST, unregistred user!
我在做串口通信程序时约定了84个字节的接口协议,在DELPHI 6下严格按类型的大小定义了如下
的记录结构,可是拆开来计算大小都是对的,比如Smallint是2字节,Longint是4字节,但是
在计算这个结构大小时确总是得到92字节,不知道哪多出了8个字节,请大家帮忙看看。
TDateRec = record
StartCode: Smallint;
DateTypeCode: Smallint;
RecordLength: Smallint;
EquipmentCode: array [0..29] of char;
AimCode: array [0..9] of char;
SerialNumber:Longint;
DateType: Shortint;
Validity: Smallint;
Hour: Shortint;
Minute: Shortint;
Second: Shortint;
Millisecond: Smallint;
Longitude: Longint;
Latitude: Longint;
Azimuth: Smallint;
Course: Smallint;
Speed: Smallint;
Warp: Smallint;
X: Longint;
Y: Longint;
Z: Smallint;
EndCode: Smallint;
end;
 
TDateRec = packed record //*** 用packed关键词生成紧凑的结构体
StartCode: Smallint; // 2
DateTypeCode: Smallint; // 2
RecordLength: Smallint; // 2 sum: 6
EquipmentCode: array [0..29] of char; //30 sum: 36
AimCode: array [0..9] of char; //10 sum: 46
SerialNumber:Longint; // 4 sum: 50
DateType: Shortint; // 1
Validity: Smallint; // 2
Hour: Shortint; // 1
Minute: Shortint; // 1
Second: Shortint; // 1 sum: 56
Millisecond: Smallint; // 2
Longitude: Longint; // 4
Latitude: Longint; // 4 sum: 66
Azimuth: Smallint; // 2
Course: Smallint; // 2
Speed: Smallint; // 2
Warp: Smallint; // 2 sum: 74
X: Longint; // 4
Y: Longint; // 4 sum: 82
Z: Smallint; // 2
EndCode: Smallint; // 2 sum: 86
end;
 
太麻烦了,不过很详细了,我给一句:
SizeOf(TDateRec)
就行了,答案确实是: 86
 
我搞错了,是86个字节,确实如creation-zy写的,多谢
 
后退
顶部