[Gambas-user] Pass arguments by reference?

Grahame White grahame at ...457...
Sat May 15 20:04:13 CEST 2004


> Of course, you could also just declare the variable as public
> and/or static and then it's kinda moot.
>
> Rob
>
>

True, but that does make it a little more awkward for making a generic 
function.

A highly contrived example follows

public function inc(input as integer) as integer
    ' increase input by 1 and return input * 2

   input = input + 1

    return input * 2

end

public sub main()

    dim i as integer
    dim j as integer

    i = 1
    j = 2

    print inc(i) ' i == 2 displays 4
    print inc(j) ' j == 3 displays 6

end

Of course the above wouldn't work if input were passed ByVal and would 
require two functions or as you say declaring i and j as public but that 
isn't good practice, not at all ;)

Grahame




More information about the User mailing list