[fpc-pascal] Pointer question

Tomas Hajny xhajt03 at hajny.biz
Wed Aug 9 22:54:00 CEST 2023


On August 9, 2023 at 22:14:17 +0200, Hairy Pixels via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
>Playing around I had a more questions about pointer operations I've never used myself.
>
>1) what does "i := x - x;" do and what is it's purpose and why doesn't "x + x" work the same?

Pointer subtraction is a reverse operation to adding a number to a pointer; the result of the subtraction is the offset between the two pointers.


>2) I've used pointer equality of course but what does "x > p" do and what is its purpose?

Relative position between the two locations in memory? As an example, it may be used to check whether a particular pointer points to a location between the start and the end of an allocated memory block (obviously, you'd need two comparisons for that).

Tomas



More information about the fpc-pascal mailing list