array questions . . .
Don Pomplun
Posts: 116
can I:
1. have multidimensional arrays? e.g. VAR byte XX[noparse][[/noparse]20,2]
2. have arrays of constants? e.g. CON XX = 1,2,3
3. initialize VAR arrays simply? e.g. VAR byte XX = 1,2,3
syntaces I've tried don't seem to take. TIA,
suggested alternatives or refrences welcome.
-- Don
1. have multidimensional arrays? e.g. VAR byte XX[noparse][[/noparse]20,2]
2. have arrays of constants? e.g. CON XX = 1,2,3
3. initialize VAR arrays simply? e.g. VAR byte XX = 1,2,3
syntaces I've tried don't seem to take. TIA,
suggested alternatives or refrences welcome.
-- Don
Comments
var long xx[noparse][[/noparse]0]
con a=10, b=20, c=30
I wonder if that will that make XX[noparse][[/noparse]0] be 10, XX be 20 and XX be 30 ??
-- Don
1) No, although it's really easy to either do multiple dimension subscripting with one dimensional arrays or implement an array object where you have
a function for producing a value (XXvalue(20,2)) or for storing it (XXsave(20,2,value)).
2) You can have constant tables in a DAT section and the compiler takes the element size from the declaration of the first item in the table
(XX long 1,2,3) and will let you use subscript notation to access the elements.
3) Easiest is to use a constant table in a DAT section, just change the values from your Spin code with the usual subscript notation. The only place
where there's a significant difference between these two approaches is when there are multiple instances of the same object. There's a unique VAR
section set up for each instance, but only one shared DAT section.
Mike
To expand on Mike's #1, to put a 2D array in a 1D array use [noparse][[/noparse]i+j*xdim] where i,j is your index and xdim is the number columns, the total size is [noparse][[/noparse]xdim*ydim].
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Post Edited (Paul Baker (Parallax)) : 1/23/2007 10:45:39 AM GMT
e.g.
VAR
byte xx[noparse][[/noparse]0]
byte A, B, C
XX[noparse][[/noparse]0] will be the same as A, XX as B, etc.
(unless I read it wrong -- still didn't help initialize the arrys, though)
Thanx for the hints on DAT. I'll work that for a while.
-- Don
myarray[noparse][[/noparse]y*xdim+x]
[noparse]:)[/noparse]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.mikronauts.com - a new blog about microcontrollers
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.