[fpc-pascal] Pointer question
Elmar Haneke
elmar at haneke.de
Thu Aug 10 10:52:49 CEST 2023
> 1) what does "i := x - x;" do and what is it's purpose and why doesn't "x + x" work the same?
Subtracting pointers may be useful if they point to consecutive memory.
The Result is the number of bytes between both addresses.
Adding pointers is useless, you would get a pointer pointing to some
address in address space which has no relation to the pointers —
presumably accessing it would rise an error.
Therefore, it is a good idea to let the compiler prevent such mistakes.
> 2) I've used pointer equality of course but what does "x > p" do and what is its purpose?
It may be useful if pointers do point into a continuous data object,
e.g. a write-pointer inside a buffer.
Elmar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20230810/c3890ce7/attachment.htm>
More information about the fpc-pascal
mailing list