I think I found a bug in the PureBasic compiler.
When modifying a string variable from within a procedure that returns a string
and then appending the returned string to the same variable,
the modifications done by the procedure are lost.
I'm using PureBsic 5.60 64 bit on Windows 7 SP1 64 bit.
The following code will demonstrate this problem:
Code: Select all
Procedure.s returnstring(*s.String)
*s\s + "abc"
ProcedureReturn "xyz"
EndProcedure
*mystr.String = AllocateStructure(String)
; This is line optional.
; The bug is independent of whether a value has been assigned to the string or not.
*mystr\s = "123"
; This is where the bug occurs.
; This line calls the function returnstring() which first appends "abc" and then returns "xyz".
; When the returned string is appended, the "abc" is lost.
*mystr\s + returnstring(*mystr)
; This is a workaround using a temporary string.
; temp$ = returnstring(*mystr)
; *mystr\s + temp$
; Should be "123abcxyz", but is actually "123xyz".
Debug *mystr\s
However, the bug also occurs when using a simple global variable, like in the follwing example:
Code: Select all
Global string$
Procedure.s returnstring()
string$ + "abc"
ProcedureReturn "xyz"
EndProcedure
string$ = "123"
string$ + returnstring()
; Should be "123abcxyz"
Debug string$
Cheers
Nils