[fpc-pascal] Why use pointers to arrays?

Marc Weustink marc at dommelstein.net
Mon Oct 12 19:43:47 CEST 2009


Graeme Geldenhuys wrote:
> On 11/10/2009, Andrew Brunner <andrew.t.brunner at gmail.com> wrote:
>>  FPC forces the ^ operator while accessing structures as pointers.
>>  Delphi didn't force it and I even suspect that memory leaks can result
>>  in NOT using the ^ to denote the reference to the pointer rather than
>>  the pointer itself.
> 
> This was just discussed in another thread. This is not always forced by FPC.
> eg:
> 
> var
>   S:  TMyArray;
>   pS: ^TMyArray;
> 
> then use them as follows:
> 
>   S[2]
>   pS[2]
> 
> Both work just fine without dereferencing the second line. Weird
> behaviour, but true.

However they have a different meaning.

assume TMyArray=array[1..10] of Byte;

then S[2] refers to the second element of S, being the second byte, 
while pS[2] refers to the 3 element of pS, being the 3rd TMyArray


Marc




More information about the fpc-pascal mailing list