[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 155
  • Last Modified:

Fields in a record don't add up

Hi Ppl

I have the following records...

semicircle_record=record
  lat,
  lon:longint;
end;

p_d100_waypoint_record=^d100_waypoint_record;
d100_waypoint_record=record
    identifier:array[1..6] of char;                        { identifier }
    position:semicircle_record;                        { position }
    unused:cardinal;                              { should be set to zero }
    comment:array[1..40] of char;                  { comment }
end;

and

p_byte_array=^byte_array;
byte_array=array[1..max_buffer_size] of byte;

var
  waypoint_record:d100_waypoint_record;

The following data is read into a instance of waypoint_record ...

48,51,56,32,32,32 which should fit into 'identifier'

128,93,179,36 which should fit into position.lat

255,21,96,254 which should fit into position.lon

0,0,0,0 which should fit into unused

and the string '14-apr-2005' should be at the start of comment.

This is the order of bytes that appear in a dump with the expression p_byte_array(@waypoint_record)^ in other words as it should. But if I view the record in a watch for some reason bytes 7 and 8 are mising as if they were deleted and the remaining data moved down.

What I mean is the first 6 bytes appear correctly in 'identifier', but the 4 bytes in position.lat are 179,36,255,21 and the 4 bytes in position.lon are 96,254,0,0 and the 4 bytes in unused are 0,0,49,52 and the comment string starts '-apr-2005'.

I'm really confused, so can anybody help?

TIA
0
andru
Asked:
andru
  • 2
  • 2
1 Solution
 
pritaeasSoftware EngineerCommented:
I think you should use

packed record

instead of

record. Then you will get what you want. See the OLH for details.
0
 
andruAuthor Commented:
Thanks.

BTW why is packed neccessary?

Andrew
0
 
pritaeasSoftware EngineerCommented:
A packed record does not store the overhead of field-separators, as is normal in common record's.

Try the following

T1 = record
  a: char;
  b: longint;
  c: byte;
end;

T2 = packed record
  a: char;
  b: longint;
  c: byte;
end;

If you use sizeof(T1) and sizeof(T2), you'll see that the sizes differ. sizeof(t2) should return 6 (6 bytes): 1 for the char, 4 for the longint and 1 byte for the byte.
0
 
andruAuthor Commented:
Probaly aligned for words and double words.

Thanks
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now