VarPtr : What's it for?

BlitzMax Forums/BlitzMax Beginners Area/VarPtr : What's it for?

tonyg(Posted 2004) [#1]
From a couple of days checking Bmax there is a shedload of stuff that my 'basic' background hasn't prepared me for.
(if anybody knows a good guide to pointers, methods, abstracts etc... I'd appreciate it).
However, I'm checking VarPtr and I'm surprised the example
returns 20 and not the address of the variable...
' few additions but basically the supplied code
Rem
Varptr returns the address of a variable in system memory.
End Rem
Local a:int
Local name:string
Local b:Int Ptr
Local p:string Ptr
a=10
name="Tony"
p=Varptr name
b=Varptr a
Print p[0]
Print b[0]

If varptr DOES return the variable value then what's it used for?


dan_upright(Posted 2004) [#2]
try adding:
Print Int(p)
Print Int(b)
at the bottom of that example


tonyg(Posted 2004) [#3]
Thanks Dan, That works.
The doc example is a bit 'loose' suggesting varptr will put the address of 'a' into 'p'.
What does 'print int(p)' do and why is it needed in this
example?


dan_upright(Posted 2004) [#4]
"p" returns the address, "p[0]" returns the variable at the address

the reason for "print int(p)" is that "print p" gives an "Unable to convert from 'String Ptr' to 'String'" error


tonyg(Posted 2004) [#5]
Good stuff. Many thanks


ImaginaryHuman(Posted 2004) [#6]
Yah, was gunna say, if you put [0] you read the content not the address