Shop OBEX P1 Docs P2 Docs Learn Events
SPIN - variable arrays + .word[] or .byte[] suffix question — Parallax Forums

SPIN - variable arrays + .word[] or .byte[] suffix question

Agent420Agent420 Posts: 439
edited 2008-05-05 13:35 in Propeller 1
This wasn't clear in the manual, and a quick search here didn't bring up anything similar...

If I have a long variable array, then want to access the high/low words from that variable, I thought I could do this:

VAR
· long matrix[noparse][[/noparse]20]

PUB main | x, y
· x := matrix[noparse][[/noparse]1].word[noparse][[/noparse]0]
· y := matrix[noparse][[/noparse]1].word[noparse][[/noparse]1]


But that fails during compilation with an 'Expected end of line' error at the period between matrix[noparse][[/noparse]1] and word[noparse][[/noparse]0]

I'm guessing you cannot combine the two on one line, as I eventually tried this and it worked:

PUB main | x, y, z
· z := matrix[noparse][[/noparse]1]
· x := z.word[noparse][[/noparse]0]
· y := z.word[noparse][[/noparse]1]


Is this even the best way to assign hi/lo words of a variable?· I was going to AND with a mask, but this seemed cleaner.



Post Edited (Agent420) : 5/5/2008 11:38:56 AM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-05-05 13:28
    There's only one subscript allowed which is why "matrix[noparse][[/noparse] 1 ].word[noparse][[/noparse] 1 ]" is not allowed. You could do "matrix.word[noparse][[/noparse]1<<1+1]".
  • Agent420Agent420 Posts: 439
    edited 2008-05-05 13:35
    Excuse my noobility with Spin, but how does that work?· Does the Word subscript follow the array, ie matrix.word[noparse][[/noparse]3] is lower word of matrix[noparse][[/noparse]1] (the array being zero based)?· martix.word[noparse][[/noparse]4]=upper word?
Sign In or Register to comment.