[fpc-pascal] pointer arithmetic help required
    Martin 
    lazarus at mfriebe.de
       
    Thu Oct 15 15:43:20 CEST 2009
    
    
  
Graeme Geldenhuys wrote:
> By the way, I am reading in the Table of Contents data for an OS/2 INF file.
>
>
>   
>>>   // now increment pEntry to point to next data structure
>>>   // below, .Length is in bytes
>>>   inc( pEntry, pEntry^.Length);
>>>   
>>>       
>> inc(PEntry, 1)
>>
>> since it increments by the size of the type
>>     
>
> No, I don't think that is correct. The data pContentData is pointing at,
> holds various structures of differing sizes. pEntry^.Length says that
> all data relating to one TOC entry is XXX bytes in length. That means
> the TTOCEntryStart structure itself (only 3 bytes) and various other
> structures making up the difference.
>   
If pentry differs in length, then use a byte pointer, (for which inc 
will work in bytes), and cast it onlt when you access the data.
I don't know if you can do it the other way round (eg trick inc to 
belive it's a byte pointer by casting):
 inc(pbyte(pentry), pentry.length); // no idea if that will work, never 
tried
Martin
    
    
More information about the fpc-pascal
mailing list