Author Topic: argument question  (Read 682 times)

0 Members and 1 Guest are viewing this topic.

Brian Alvarez

  • Guest
argument question
« on: November 01, 2020, 10:37:34 PM »

 Hello Charles, im trying to fix the associative array feature, so,
I have a class module that is supposed to return a string pointer. like this:


Code: [Select]
    function pStr(string k) as sys
        int i = this.getindex(k)
        return this.hBuffer + (i * 8)
    end function

When i use the class like this:

Code: [Select]
somefunction(byval asr.pStr("key"))
And try to print the value like this:

Code: [Select]
sub somefunction(string *a)
    print @a cr
    print a cr
end sub

 I get the address to a completely new variable that holds the address to the original string. What am i doing wrong?






Brian Alvarez

  • Guest
Re: argument question
« Reply #1 on: November 01, 2020, 10:41:15 PM »
As a reference... this returns a correct string:

Code: [Select]
    function cStr(string k) as string
        int i = this.getindex(k)
        static string *ps
        @ps = this.hBuffer + (i * 8)
        return ps
    end function

Charles Pegge

  • Guest
Re: argument question
« Reply #2 on: November 02, 2020, 06:12:32 AM »
Hi Brian, double pointering '**' might help:

Code: [Select]
function fs(string**s) as string
print @s
return s
end function

string t="ok"
print @t 'same as '@s' inside function fs
print fs(t)


Brian Alvarez

  • Guest
Re: argument question
« Reply #3 on: November 02, 2020, 01:33:59 PM »

 That worked! Thanks Charles. :)