http://www.purebasic.fr/english/viewtop ... 58#p291358
to get the terms clarified:
Now I would like to have a way to get the address of a normal string variableTrond wrote:What is *This.String? Is it a pointer? Yes.
Is it a pointer to string data? No!
Is it a pointer to a string variable? Yes!
What does @String do? Receive a pointer to the string variable? No!
@String (or @"String") receives a pointer to the string data.
*This.String is a pointer to a structure which contains a single string variable.
like mystring.s.
I can get the address of a string variable inside a structure,
like this code sample demonstrates:
Code: Select all
EnableExplicit
Structure val_struct
a.i
b.i
c.s
d.i
EndStructure
Global structVar.val_struct
Global *String.String
Global stringVar.s = "kat"
*String = @structVar + OffsetOf(val_struct\c) ; <--- get the adress of structVar\c
structVar\c = "hxsesi"
Debug *String\s
*String\s = "looooooooooooooooooooong"
Debug structVar\c
structVar\c and *String\s are "the same".
Is there any way to get the address of f.e. stringVar.s?
([The address of] a new pointer to the character data of the string
will of course not suffice, as it gets invalid
once the character data needs to be relocated!)
---------------------------------------------------
Edit for future visitors

I did find ways to "obtain the address of" string variables,
but none of them seems to be more usefull for me
than to use string structures (like stsMyStringStruct.String)
instead of string variables (like strMyString.s) in the first place
if you will want to use the address of the variable at some point
(like when you want to pass the string ByRef).
Nevertheless I'll give an example, in case that can be usefull
to someone:
Code: Select all
EnableExplicit
; This will copy the address of the variable var into the pointer ptr:
Macro AddrToPtr(var, ptr)
EnableASM
LEA eax, var
MOV ptr, eax
DisableASM
EndMacro
Define strX.s
Define *ptrstrX.String
strX = "dog"
Debug strX ; dog
AddrToPtr(strX, *ptrstrX)
*ptrstrX\s + "s run around a lot."
Debug strX ; dogs run around a log.
and so do pointers to them!