where does VarPtr point to?

BlitzMax Forums/BlitzMax Programming/where does VarPtr point to?

Thanks for your posts!

Indeed, a Byte[] seems to be the same as a pointer to its first element - the following test illustrates this:
local Text:Byte[] = [byte(0),byte(1),byte(2),byte(3),byte(4),byte(5),byte(6),byte(7)]
local TextPtr:Byte Ptr = Text
print(TextPtr[0]+","+TextPtr[1]+","+TextPtr[2]+","+TextPtr[3])
print(TextPtr[4]+","+TextPtr[5]+","+TextPtr[6]+","+TextPtr[7])

yields

0,1,2,3
4,5,6,7

as expected. On the other side, a similar code
local Text:String = "abc~0def"
local TextPtr:Byte Ptr = Text

is rejected by the compiler - and
local Text:String = "abc~0def"
local TextPtr:Byte Ptr = VarPtr Text
print(TextPtr[0]+","+TextPtr[1]+","+TextPtr[2]+","+TextPtr[3])
print(TextPtr[4]+","+TextPtr[5]+","+TextPtr[6]+","+TextPtr[7])

produces

16,211,102,0
104,255,168,0

which is *not* what you would expect.