Well, it does. Of course the pseudotype is necessary (else I wouldn't have included it), but it does work. Just don't pass a combined string (a+b) to the procedure.Except that it doesn't
Getting address of string constants with @ or ?
- tinman
- PureBasic Expert
- Posts: 1102
- Joined: Sat Apr 26, 2003 4:56 pm
- Location: Level 5 of Robot Hell
- Contact:
You didn't use a pseudotype you used a normal string type (.s).Trond wrote:Well, it does. Of course the pseudotype is necessary (else I wouldn't have included it), but it does work. Just don't pass a combined string (a+b) to the procedure.Except that it doesn't
Using this code from your function:
Code: Select all
Procedure Callback(FileAddress.l)
Debug PeekL(FileAddress) ; Guaranteed to be different for each file
Debug PeekS(PeekL(@FileAddress))
EndProcedure
Prototype ProtoCallbackInterface(FileAddress.s)
Function.ProtoCallbackInterface = @Callback()
string.s = "foo"
Debug "@string = " +Str(@string)
Debug "@"+Chr(34)+"foo"+Chr(34)+" = "+Str(@"foo")
Debug "Result of Function(string)"
Function(string)
Debug "Result of Function(@"+Chr(34)+"foo"+Chr(34)+")"
Function("foo")
Code: Select all
@string = 9045608
@"foo" = 4280824
Result of Function(string)
7274598
foo
Result of Function(@"foo")
7274598
foo
Worse still, if you return this value and try to use it you get an invalid memory access (put this code at the end of the above and run it):
Code: Select all
*foo.c = Function("foo")
Debug "*foo = "+Str(*foo)
Debug PeekS(*foo)
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
(WinXPhSP3 PB5.20b14)
Sorry, I forgot an @. And when I add the @ I can remove the Peekl(). So this is the correct code (with example):
Code: Select all
Procedure Callback(FileAddress.l)
Debug FileAddress ; Guaranteed to be different for each file
Debug PeekS(FileAddress)
EndProcedure
Prototype ProtoCallbackInterface(FileAddress.s)
Function.ProtoCallbackInterface = @Callback()
string.s = "Hello"
Debug @string
Function(string)
Debug "---"
Function(#PB_Compiler_File)
Take a look at the generated assembly code to see what PureBasic is doing.PureBasic is copying the string data to the local variable.