[fpc-pascal] memory layout of arrays

Jerry lanceboyle at qwest.net
Thu Sep 14 11:20:23 CEST 2006


On Sep 14, 2006, at 2:00 AM, Marc Santhoff wrote:

> Hi,
>
> when using arrays in C the layout of arrays is sort of flat, since
> pointer arithmetics for accessing values works (e.g. "pointer += 4"  
> for
> 32 bit values).
>
> Is this the same for pascal/fpc? Do values of for example an integer
> array sit in memory at 4 Byte boundaries?
>
> I need to hand over arrays to a C library and have no influence on how
> access is done internally (still und investigation). Currently the  
> C lib
> reads garbage from my array ...

FWIW, GPC arrays seem to be laid out exactly like those for C. I have  
passed arrays to and from Ada by specifying "C conventions," so at  
least with GPC things went well. I haven't tried this with FPC,  
however. Beware of 2D arrays in C because there seems to be no  
requirement in C that all of the data be allocated in contiguous  
memory; the parts of the 2D array (most likely, rows) can in effect  
be fragmented. I am told that some or most C compilers do allocate  
the memory as one big chunk, however.


> TIA,
> Marc
>




More information about the fpc-pascal mailing list