How to initialize arrays
peterz
Posts: 59
I have used a naive way to initialize arrays because I don't know how to delcare an array and initialize it at the same time.
I do:
BYTE MyArray[noparse][[/noparse]5]
MyArray[noparse][[/noparse]0]:=$23
MyArray[noparse][[/noparse]1]:=$20
MyArray[noparse][[/noparse]2]:=$11
MyArray[noparse][[/noparse]3]:=$21
MyArray[noparse][[/noparse]4]:=$AA
I wanted to do something like:
BYTE MyArray[noparse][[/noparse]5]=$23,$20,$11,$21,$AA
How can I do it in Spin ?
I do:
BYTE MyArray[noparse][[/noparse]5]
MyArray[noparse][[/noparse]0]:=$23
MyArray[noparse][[/noparse]1]:=$20
MyArray[noparse][[/noparse]2]:=$11
MyArray[noparse][[/noparse]3]:=$21
MyArray[noparse][[/noparse]4]:=$AA
I wanted to do something like:
BYTE MyArray[noparse][[/noparse]5]=$23,$20,$11,$21,$AA
How can I do it in Spin ?
Comments
MyArray BYTE $23,$20,$11,$21,$AA
And then you would use it from Spin code like any other array: MyArray[noparse][[/noparse]index]
But be aware that no aligning takes place. ie. if you have an array of longs (or just plain longs), they may be at address $13 and whatnot, ie. addresses that aren't divisible by 4 and therefore not accessible by rdlong (and maybe some spin commands, I don't really know about spin, but assignment and comparing and stuff seems to work.)
EDIT: You should of course leave out the BYTE MyArray[noparse][[/noparse]whatever]. If you want an array longer than the value it should be initialized to, add zeros after the BYTE (or WORD or LONG) in DAT to make a larger array.
Post Edited (Jasper_M) : 1/10/2007 7:22:58 PM GMT
I am trying to modify them without success.
I pass the array to another OBJ with @MyArray.
It works as expected, but then I try to modify the values with:
MyArray:=$55
And call again the other object. But it keeps the old value!
Is this normal ?
When passing it as parameter:
PUB Function(Pointer)
BYTE[noparse][[/noparse]Pointer][noparse][[/noparse]Index] := something
And it'd be called with @MyArray as argument,.
So, if I pass the array as a pointer as follows it wont work ?
MyFunction(@MyArray)
BYTE b
MyFunction(array)
b := array[noparse][[/noparse]0]
Would I need the following:
BYTE b
MyFunction(array)
b := BYTE[noparse][[/noparse]array][noparse][[/noparse]0]
???
Post Edited (peterz) : 1/10/2007 8:04:57 PM GMT