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:
*s\s + "abc"
*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".
The above example uses a string member of a dynamically allocated structure, because this is what my actual program does as well.
However, the bug also occurs when using a simple global variable, like in the follwing example:
string$ + "abc"
string$ = "123"
string$ + returnstring()
; Should be "123abcxyz"
I hope this is a bug (and not a feature
) and that it will get fixed soon, but there's no hurry.