Author Topic: Another direct string oddity.  (Read 922 times)

0 Members and 1 Guest are viewing this topic.

Brian Alvarez

  • Guest
Another direct string oddity.
« 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.

Charles Pegge

  • Guest
Re: Another direct string oddity.
« Reply #1 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