Strings and Pointers!

BlitzMax Forums/BlitzMax Programming/Strings and Pointers!

Scaremonger(Posted 2013) [#1]
The below piece of test code works just how I need it to for numerical values:

but when it comes to strings it is a whole different ball game. Using the same approach simply doesn't work:

Does anyone know if it is possible to have two variables referencing the same string data in Blitzmax?

Thanks in advance...
Si...


Scaremonger(Posted 2013) [#2]
A simpler test example:
Global data% = 111
Global other:Int Ptr = Varptr data

data = 2222

Print " data: " + data
Print " other:" + Int(other[0])

other[0] = 333

Print " data: " + data
Print " other:" + Int(other[0])



Jesse(Posted 2013) [#3]
the problem with strings is that strings are objects it's not an actual address to data.
with strings you get the address to the string object with all it's overhead. Also the bytes are not directly accessible through a pointer.


Who was John Galt?(Posted 2013) [#4]
Not sure about the FromCString stuff. It's a Blitz string, not a C string. Can you just cast the pointer to a string pointer and index it with [0]?

No Blitz here, so untested, just something to try.


Scaremonger(Posted 2013) [#5]
@Jesse - Yep. Thought so.

@John Galt - That piece of code was the latest failed attempt at getting something out of it.

I think I need to start looking at CStrings!

Cheers for your comments.


Azathoth(Posted 2013) [#6]
However you're not even using the same approach. In the first you're taking the address of a variable and modifying its contents, in the second you're taking the address of variable then overwriting that with the address of a second variable.