For the following code
[code]
//building in Xojo2017r1.1 for Win 32 bit
dim p1,p2,p3 as ptr
p1=p2+p3 //compiles fine
p1=p2-p3 //Type mismatch error. Expected Ptr but got Int32[/code]
ptr addition compiles fine, but ptr subtraction throws a compile error.
Is this expected behaviour? If so, why is subtraction different to addition?
Eli_Ott
(Eli Ott)
2
Because subtracting a pointer from another pointer returns an integer for the distance or offset.
Norman_P
(Norman P)
4
this make sense because the result of - is a delta (an offset between the two addresses) not a Ptr (ie a valid address)
Eli_Ott
(Eli Ott)
5
But you cannot add an Integer (a delta or offset) to a Ptr it will not compile:
Dim p As Ptr
Dim i As Integer
Dim result As Ptr = p + i
Why is this?
because it’s likely to cause problems?
You can cast to integer, add something and cast to ptr.