Oxygen Basic

Information => Development => Topic started by: Brian Alvarez on June 03, 2019, 06:12:14 PM

Title: Another direct string oddity.
Post by: Brian Alvarez on June 03, 2019, 06:12:14 PM

 I think this may be a feature, but its not very intuitive...

Code: [Select]
function getsubresult(string s) as string
    s += ". Thanks!"  ' this seems to think i passed a literal
    return s
end function

function getresult(int v, string s) as string
    string ss = s
    ss = "Hello " + s + " you owe me " + str(v)   
    return getsubresult(bycopy ss) ' bycopy has no effect.

end function

print getresult(123, "Brian")

 Why does getsubresult complain if i am not passing a literal string? i am even passing it by copy to no avail.
stating byref in the getsubresult fixes it, but i dont see a reason to explicitly do so...

 Probably not a bug, but then again, this is not a bug report, just a thought.
Title: Re: Another direct string oddity.
Post by: Charles Pegge on June 04, 2019, 04:26:46 AM
The solution is to pass the string by reference. And using Bycopy ensures the original string is not altered by the function, only the copy.

function getsubresult(string *s) as string