Possible array copy bug?
Posted: Sat May 06, 2006 5:26 pm
If you copy an array without specifying the element (ie a2()=a1() ) then both arrays point to the same memory space, so if you subsequently change either array both are updated.
Not sure if this should be a compile error, or if the array contents should be copied (which would be nice
)
Not sure if this should be a compile error, or if the array contents should be copied (which would be nice

Code: Select all
Dim a1.l(10)
Dim a2.l(10)
OpenConsole()
;initialize arrays
For i = 1 To 10
a1(i) = i + 100
a2(i) = i + 200
Next i
PrintN("Initialized...")
;show the array values
For i = 1 To 10
PrintN("a1("+Str(i)+") = "+Str(a1(i))+" : a2("+Str(i)+") = "+Str(a2(i)))
Next i
a2()=a1()
a1(5) = 55555
a2(7) = 77777
PrintN("")
PrintN("a2()=a1(), a1(5) and a2(7) changed...")
;show the array values
For i = 1 To 10
PrintN("a1("+Str(i)+") = "+Str(a1(i))+" : a2("+Str(i)+") = "+Str(a2(i)))
Next i
Print("Hit <RETURN> to exit")
Input()
CloseConsole()