View Full Version : SPIN - variable arrays + .word[] or .byte[] suffix question

05-05-2008, 06:27 PM
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:

long matrix[20]

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

But that fails during compilation with an 'Expected end of line' error at the period between matrix[1] and word[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[1]
x := z.word[0]
y := z.word[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

Mike Green
05-05-2008, 08:28 PM
There's only one subscript allowed which is why "matrix[ 1 ].word[ 1 ]" is not allowed. You could do "matrix.word[1<<1+1]".

05-05-2008, 08:35 PM
Excuse my noobility with Spin, but how does that work? Does the Word subscript follow the array, ie matrix.word[3] is lower word of matrix[1] (the array being zero based)? martix.word[4]=upper word?