Shop OBEX P1 Docs P2 Docs Learn Events
Variable Accessors — Parallax Forums

Variable Accessors

Vega256Vega256 Posts: 197
edited 2011-05-27 12:49 in Propeller 1
Hey,

So suppose that I have an array of 10 longs and I wanted to access the first byte of the first element. Could I do this?
someLong [10]

someLong [0].byte [0] := someValue

Would be better to just declare an array of 320 bytes?

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-05-27 12:25
    No, but you can do this:
    byte[@someLong[0]][0] := someValue
    
    

    BTW, I'm not sure why your version isn't allowed. It's a perfectly reasonable syntax.

    -Phil
  • Vega256Vega256 Posts: 197
    edited 2011-05-27 12:32
    No, but you can do this:
    byte[@someLong[0]][0] := someValue
    
    

    BTW, I'm not sure why your version isn't allowed. It's a perfectly reasonable syntax.

    -Phil
    The compile error says "Variable needs an operator". There may be something else wrong in my code. Instead of immediate data for the indices, though, I do have variables.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-05-27 12:35
    I guess you'll need to post your entire program if that gave you an error.

    -Phil
  • Mike GreenMike Green Posts: 23,101
    edited 2011-05-27 12:49
    You can use someLong.byte[ 0 ] where the subscript is a byte offset from the beginning of someLong. If you might want to say someLong[ x ].byte[ 2 ], you'd have to use someLong.byte[ x*4+2 ] or someLong.byte[ x<<2+2 ].
Sign In or Register to comment.