[Lazarus] C Integer types

Bernd prof7bit at gmail.com
Mon Jul 9 09:40:28 CEST 2012


Your explanations about pointers are 100% correct but it is not clear
why you are interleaving them with my other explanations which makes
it look as if you were trying to correct my comments but since there
is nothing wrong with my comments, they are not conflicting, it is
impossible to correct any mistakes. This will only confuse the reader.

2012/7/9 Hans-Peter Diettrich <DrDiettrich1 at aol.com>:

>> Its really just a simple record with 4 numbers in it.
>
> With 4 pointers in it, aligned to 8 byte boundaries.

No, it contains the numbers directly. There are no pointers in the
data. This other translation:

type
  PInt32 = ^Int32;

var
  data: Pointer;
  seqence_crc: Int64;
  seqence_key: Int64;
  compr_crc: Int64;
  compr_len: Int32;

begin
  seqence_crc:=PInt64(data)^;
  seqence_key:=PInt64(@data[8])^;
  compr_crc:=PInt64(@data[16])^;
  compr_len:=PInt32(@data[24])^;

based on the one from Marco in the second mail (I only changed the
type of compr_len) which is also correct also clearly shows (clearly
because its written in a readable language) that its just simply
reading the values directly from the buffer whose address (the pointer
to its first byte) is given in the variable data.

My initial translation with the record was 100% correct. Here it is
again, this time using the IntXX type names for better comparison:

type
  PDataHeader = ^TDataHeader;
  TDataHeader = record
    sequence_crc: Int64;
    sequence_key: Int64;
    compr_crc: Int64;
    compr_len: Int32;
  end;

var
  data: PDataHeader;

The variable data would then be of type PDataHeader (I assume it is a
header of something, so data would point to the first byte of that
"something") and accessing the sequence_crc would go like this:

data^.sequence_crc

or if you enable autoderef it becomes even nicer:

data.sequence_crc

Bernd




More information about the Lazarus mailing list