<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>FWIW, when I added similar functionality to my Stanford Pascal
compiler, I chose not to allow arithmetic <br>
of pointers, but instead I added some functions: <br>
</p>
<p>PTRADD (p, i) - p is type ANYPTR, i is integer, result is of type
ANYPTR<br>
PTRDIFF (p1, p2) - two pointers, the result is integer<br>
ANYPTR is a predefined type, compatible with every (typed pointer)
<br>
ADDR (x) is a function (borrowed from PL/1), which returns an
ANYPTR ... and it is allowed for all types of variables<br>
PTRCAST is the same as PTRADD (p, 0) - and is used to cast
pointers between incompatible pointers (not type safe) <br>
</p>
<p>Kind regards</p>
<p>Bernd <br>
</p>
<p><br>
</p>
<div class="moz-cite-prefix">Am 10.08.2023 um 10:52 schrieb Elmar
Haneke via fpc-pascal:<br>
</div>
<blockquote type="cite"
cite="mid:5b9bdf0b-62b8-4fa0-832d-36db731b2c60@haneke.de">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<span style="white-space: pre-wrap">
</span>
<blockquote type="cite"
cite="mid:5A8CD9DB-1FC7-48FF-A878-7563A964F4B0@gmail.com">
<pre class="moz-quote-pre" wrap="">1) what does "i := x - x;" do and what is it's purpose and why doesn't "x + x" work the same? </pre>
</blockquote>
<p>Subtracting pointers may be useful if they point to consecutive
memory. The Result is the number of bytes between both
addresses.</p>
<p>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.</p>
<p>Therefore, it is a good idea to let the compiler prevent such
mistakes.<br>
</p>
<blockquote type="cite"
cite="mid:5A8CD9DB-1FC7-48FF-A878-7563A964F4B0@gmail.com">
<pre class="moz-quote-pre" wrap="">2) I've used pointer equality of course but what does "x > p" do and what is its purpose? </pre>
</blockquote>
<p>It may be useful if pointers do point into a continuous data
object, e.g. a write-pointer inside a buffer.</p>
<p>Elmar</p>
<br>
</blockquote>
</body>
</html>