[fpc-pascal] 2D Dynamic arrays and BlockRead

Jürgen Hestermann juergen.hestermann at gmx.de
Fri Dec 3 17:26:47 CET 2010


andrew.bennett at ns.sympatico.ca schrieb:
> After using BlockRead to fill a 2D dynamic array, I get an access violation on the 
> very first reference. A 2D array with only one dimension dynamic works OK.
> What am I missing?
>   
Maybe you blundered into the same trap as so many others who do not know 
that dynamic arrays are *pointers* (to arrays). It is one of the sins 
done by Borland to abandon the once strict logic that in Pascal the 
syntax is always context independend. Now this is no longer the case 
(i.e. for dynamic arrays).

in your example

  STat  = Array[0..W-1] Of Single ; { Static array }
  DST = Array Of STat ; { One dimension dynamic, the other static }
  D2T = Array Of Array Of Single ; { Two dynamic dimensions }

STat always means the address starting with STat[0] (context independend).
Also DST always means the address where DST[0].
But D2T is a pointer which can be either the the address of the pointer 
(in all low level routines like fillchar, sizeof, BlockRead/-Write etc.) 
but also can be the address of the D2T[0] because you can refer to 
elements without the need to dereference it as in D2T^[0].



More information about the fpc-pascal mailing list