Array problems
Lucky
Posts: 98
Is it possible for one array of variables to write to another array of variables by accident if you go over the first array's size? For example, if you had myArray[noparse][[/noparse]45] and myArrayTwo[noparse][[/noparse]60], and you had a repeat statement that wrote numbers in myArray from index 0 to 49, would 45-49 numbers overflow into myArrayTwo?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"You do not really understand something unless you can explain it to your grandmother."
-Lucky[size=-1][/size]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"You do not really understand something unless you can explain it to your grandmother."
-Lucky[size=-1][/size]
Comments
It's more complicated than that though -- the PropTool also rearranges your vars to group them by type starting with all the longs, then all the words, then finally all the bytes to keep everything aligned in Hub RAM without waste. So if MyArray is type Word and MyArrayTwo is type Long, MyArray will step on some totally different data if you overflow it.
This is annoying and totally not like most versions of BASIC, but it is like most C-based languages which are used for a lot of important work in the world.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"You do not really understand something unless you can explain it to your grandmother."
-Lucky[size=-1][/size]
What about overwriting SPIN or PASM code ... or the first 16 bytes of HUB-RAM containing the clock frequency and some important pointers ...
You see ... anything can happen when you exceed the limit of an array positive or maybe with a negative index?! ... What can happen is unpredictable. The worst is switching input-pins to be an output. Depending on the hardware attached to those pins you can fry the prop and/or external hardware.
·