This sample allocates an array as local variable. A global variable referenced by the function argument is set to reference the array. Note that it is not the local variable a is the one that references the array, but rather the global variable that is referenced by a,namely q. If we wanted a to reference the array z then we could use undef a before the ref statement.
When the function returns the array is not released when the local variables are released, because there is a reference to it (variable q) and thje program prints the elements of q.
Example reftest2.bas :
ref a = z
end sub
sub testi(h)
test h
end sub
testi q
for i=1 to 10
print i,". ",q[i],"\n"
next i
sub test(a)
local z,i
for i=1 to 10
z[i] = i
next
Result executing reftest2.bas :
Possible error messages sent to stderr: