[Lazarus] C Integer types
Bernd K.
prof7bit at gmail.com
Sun Jul 8 21:39:46 CEST 2012
On 08.07.2012 17:18, Hans-Peter Diettrich wrote:
> Bernd schrieb:
>> 2012/7/7 Marco van de Voort <marcov at stack.nl>:
> IMO all these members should be pointers, of size 64 bit according to
> the index increment (8 bytes?). Typecasts will be needed for 32 bit
> pointers, as demonstrated in above code.
Wait a monment, I have again looked at it. I think I was right and my
other email admitting that I was wrong was wrong.
seqence_crc = *((int64_t*)data);
seqence_key = *((int64_t*)&data[8]);
from the inside out:
data is a pointer, say it points to a buffer
(int64_t*)data still points to that buffer
*((int64_t*)data) are bytes 0..7 of that buffer as int64.
now the second line
seqence_key = *((int64_t*)&data[8]);
data[8] is the same as *(data+8)
data[8] represents the 8th byte of that buffer (already dereferenced!)
&data[8] is the address of that byte
&data[8] would be the same as (data+8)
((int64_t*)&data[8]) is still the same pointer
*((int64_t*)&data[8]) are bytes 8..17 of that buffer as int64
this should be equivalent:
seqence_crc = *((int64_t*)&data[0]);
seqence_key = *((int64_t*)&data[8]);
compr_crc = *((int64_t*)&data[16]);
compr_len = *((int32_t*)&data[24]);
and this also:
seqence_crc = *((int64_t*)data);
seqence_key = *((int64_t*)(data+8));
compr_crc = *((int64_t*)(data+16));
compr_len = *((int32_t*)(data+24));
Its really just a simple record with 4 numbers in it.
Bernd
More information about the Lazarus
mailing list