Get an error when trying to use modifiers on array elements.
Tom_W
Posts: 4
I did a bit of searching on the forum but didn't find this exact problem. I'm not trying to alias into a specific nibble or a bit of an array of bytes, but simply use a modifier on an array element. If say arrBytes.NIB0(3) is legal and it accesses the byte array as if it was an array of nibbles (which is crafty and handy when needed) why is arrBytes(3).NIB0 an error? In my view this should be perfectly OK, but it isn't. What's the reason? Of course one walk-around is to first put the array element into a temporary variable and then use a modifier on it like in the example code below. Perhaps this could be a feature request for the next version.
The following example code will not run until offending lines are commented out.
The following example code will not run until offending lines are commented out.
' {$STAMP BS2} ' {$PBASIC 2.5} arrBytes VAR Byte(8) i VAR Byte arrBytes(0)=$10 arrBytes(1)=$32 arrBytes(2)=$54 arrBytes(3)=$76 arrBytes(4)=$98 arrBytes(5)=$BA arrBytes(6)=$DC arrBytes(7)=$FE DEBUG "arrBytes(3).NIB0=", HEX arrBytes(3).NIB0, CR 'GET ERROR: Expected ':' or end-of-line DEBUG "arrBytes(3).NIB1=", HEX arrBytes(3).NIB1, CR 'GET ERROR: Expected ':' or end-of-line 'PUTTING PARENTHESES AROUND arrBytes(3) DOESN'T WORK EITHER. DEBUG "(arrBytes(3)).NIB0=", HEX (arrBytes(3)).NIB0, CR 'STILL GET ERROR: Expected ':' or end-of-line 'HAVE TO ASSIGN arrBytes(#) TO A VARIABLE FIRST. i=arrBytes(3) DEBUG "i=arrBytes(3)=", HEX i, " i.NIB0=", HEX i.NIB0, CR 'THESE WORK OK. DEBUG "i=arrBytes(3)=", HEX i, " i.NIB1=", HEX i.NIB1, CR i=arrBytes(7) DEBUG "i=arrBytes(7)=", HEX i, " i.NIB0=", HEX i.NIB0, CR DEBUG "i=arrBytes(7)=", HEX i, " i.NIB1=", HEX i.NIB1, CR
Comments
Having that, any element of the array is still addressable using arrBytes(n), for n=0 to 7, and also as arrNibs(2n) and arrNibs(2n+1). But also simply and directly as arrByte3 or arrByte3.nib0.