I've been having trouble with a program that sometimes optimised compiles and some times doesn't
B4X:
Sub Globals
Dim a(0)
End Sub
Sub App_Start
End Sub
Sub AlSort
a() = Array ( "a", "x", "G", "c", "X", "A", "g", "C", "u", "U" )
End Sub
Sub AlToArray
End Sub
Sub Rank
Dim a(3,4,5)
End Sub
Sub Reverse
End Sub
Sub Sort
End Sub
Sub SortKeysAndItems
End Sub
When it fails it compiles the Array with the wrong rank.
B4X:
var__main_a = new String[,,] {(@"a"),(@"x"),(@"G"),(@"c"),(@"X"),(@"A"),(@"g"),(@"C"),(@"u"),(@"U")};
Whether this occurs or not is highly position dependant in the code. Remove one of those blank Subs and it will compile OK. I had various dims of a() around the code but this is as small as I can get it and still fail.
EDIT:- Damn! typoed the title yet again but Erel has quietly fixed it
While it is legal to change the size of an array, you shouldn't change its rank (number of dimensions).
Similar code will fail in previous versions as well.
Basic4ppc doesn't compile the subs in any specific order. In this case it compiles sub Rank before AlSort. Therefore it treats the array as a three dimensions array (instead of one).
Basic4ppc doesn't compile the subs in any specific order. In this case it compiles sub Rank before AlSort. Therefore it treats the array as a three dimensions array (instead of one)
Thank you Erel, I sort of thought that was what was going on. I guess it is specific to the Array keyword that looks at the existing array before assignment.
While it is legal to change the size of an array, you shouldn't change its rank (number of dimensions)
Changing rank seems to work without problems for normal Dims and assignments from libraries as they just assign a new array to the existing array variable without any checking.