[fpc-pascal] Illogical automatic dereferencing

Henry Vermaak henry.vermaak at gmail.com
Sun Oct 11 14:20:12 CEST 2009


2009/10/10 Jürgen Hestermann <juergen.hestermann at gmx.de>:
>> I can't understand what you are trying to say.  An array is a pointer
>> to where the elements of the array resides in memory.  How else do you
>> think it works?
>
> just look at:
>
> type ArrayType = array[1..10] of char;
> var  X  : ArrayType;
>     PX : ^ArrayType
>
> What is the difference between X and PX?
>
> X is an array of char which can be accessed directly. The identifier X means
> the address in memory where the array elements 1..10 are stored. The address
> of X (@X) is the address of the array (first element).
>
> XP is just a pointer to such a structure. It's not the array itself. The
> address of XP (@XP) is the address of the pointer, not the array.
>
> Sizeof(X) is 10 bytes.
> Sizeof(PX) is 4 bytes.
>
> Still you can use X[1] and PX[1]. That's illogical.

I've tested this now and could only get this behaviour with {$mode delphi}.

Henry



More information about the fpc-pascal mailing list