Shop OBEX P1 Docs P2 Docs Learn Events
Access array by reference - how to? — Parallax Forums

Access array by reference - how to?

Shane De CataniaShane De Catania Posts: 67
edited 2007-04-19 04:47 in Propeller 1
Hi All,
This is almost certainly a silly question with an obvious answer... How do I access the elements of an array passed by address to a function?
I want to do something like this...
VAR
      LONG my_array
...

PUB MAIN
    AccessArray(@my_array)
...


I want to access the array by reference-
This could be in a different cog...

PUB AccessArray(array_ptr) | x, y, z

    x := array_ptr[noparse][[/noparse]0]    ' Doesn't work
    y := array_ptr    '
    z := array_ptr    '
...



I found something like y := LONG[noparse][[/noparse]array_ptr+4] did work, but that seems rather long winded. What is the best way to read (and write) individual elements
from an address pointer?
Thanks in advance.
Cheers,
Shane

Post Edited (Shane De Catania) : 4/19/2007 4:54:44 AM GMT

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-04-19 04:47
    You found the solution, LONG[noparse][[/noparse]x] is used to dereference a pointer.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
Sign In or Register to comment.