Reverse Dereferencing?

BlitzMax Forums/BlitzMax Programming/Reverse Dereferencing?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.


Local t$="Hello"
DoSomething( t )
Assert t="Hello"

...currently, this code is guaranteed not to cause an exception since nothing can modify the string.


Yes this right. But two things:
1) Is this really really need?
2) If I really want i can change string in function DoSomething. Not so easy, but this is possible. So no guaranties.
And indexed access to string's elements is useful.

If Mark don't want do this, this don't meant that we can't do this.
Enjoy:
Local str$ = "Hello"
Print str

'getting pointer to chars:
Local p:Int Ptr = Int Ptr(Varptr(str))
Local pchar:Short Ptr = Short Ptr(p[0])
pchar :+ 6 'this offset depends on string's structure

pchar[0]=Asc("H")
pchar[1]=Asc("e")
pchar[2]=Asc(" ")
pchar[3]=Asc("h")
pchar[4]=Asc("e")

Print str