Oxygen Basic
Programming => Problems & Solutions => Topic started by: Mike Lobanovsky on September 17, 2014, 10:46:03 AM
-
Charles,
How can I swap the references of two Oxygen arrays?
Say, there are two int arrays of same size, array0[] and array1[]. At some point in my program I want to swap the references (names) of these arrays so that array0 would point to the contents of array1 and vice versa.
Is creating overlays and swapping the addresses that these overlays are pointing to the only way feasible to achieve this effect?
Thanks.
-
Maybe something like the Script BASIC REF would work with OxygenBasic. I don't under estimate the power of pointer/macro magic.
-
Yes, overlays in some form are required. Their base addresses can be swapped.
Example:
INCLUDEPATH "$\inc\"
INCLUDE "Console.inc"
macro refswap(a,b)
scope
let _a=@b
@b=@a
@a=_a
end scope
end macro
float as1[100],as2[100] 'STATIC ARRAYS
float *ar1=@as1,*ar2=@as2 'ARRAYS BYREF
'TEST
ar1[5]=1.25
printl ar1[5] " " ar2[5]
refswap(ar1,ar2)
printl ar1[5] " " ar2[5]
waitkey
-
@Charles:
Thanks much for the hint. I just wanted to be sure there's no better way. There's so much in Oxygen still hidden from the eyes of an ordinary user... :)
@John:
Yes, Oxygen's "overlays" are pretty much like SB's "ref vars" and they serve similar purposes.