Shop OBEX P1 Docs P2 Docs Learn Events
Arrays — Parallax Forums

Arrays

brsbrs Posts: 33
edited 2006-05-16 13:31 in Propeller 1
i haven't been able to try this yet (still waiting on my propeller shipment), but i was wondering if it's possible to pass arrays in/out of methods?

for example, if "a" is an array, "fido" is the object name, and "Catch" is a public method of "fido" then would the calling statement be: fido.catch(@a)?

i'm presuming references are used to pass arrays around, but i'm uncertain about the syntax used to dereference the arrays once they are passed into or out of a method or if this is even possible?

regards,
bryce

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-05-13 04:12
    Using @ is passing the address of, so yes, you can use this to pass the starting address of an array -- you could actually pass the address of an element within the array as well. The method receiving this parameter should know that it's getting an address and not a value.

    Passing the address of a variable (or block of them) is useful for letting one process (cog) update variables for another -- one process simply passes the address of the variable(s) it wants the other to have access to. This is possible because all Spin variables reside in main RAM.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • brsbrs Posts: 33
    edited 2006-05-13 14:45
    here is a very simple example (please see attached files).

    test.spin contains the "Main" public method that initializes array "a" and passes it into the "fido.Catch" method as a pointer or reference. the arrays i wish to use contain floating-point numbers.

    the "a" array will then be manipulated to obtain another array, let's call it "b", and this will be passed out of the method back to "Main".

    i finally obtained my propeller, but debugging does not yield the expected results. i don't think i'm dereferencing the arrays correctly!

    any ideas?

    Post Edited (brs) : 5/15/2006 3:37:15 AM GMT
  • brsbrs Posts: 33
    edited 2006-05-16 04:02
    does anyone have a quick example of passing an array of either integer or floating-point values into a method, manipulate those values, and then pass an array back out?
  • cgraceycgracey Posts: 14,133
    edited 2006-05-16 05:12
    I think I fixed your code. Try these.
    brs said...
    here is a very simple example (please see attached files).

    test.spin contains the "Main" public method that initializes array "a" and passes it into the "fido.Catch" method as a pointer or reference. the arrays i wish to use contain floating-point numbers.

    the "a" array will then be manipulated to obtain another array, let's call it "b", and this will be passed out of the method back to "Main".
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Chip Gracey
    Parallax, Inc.
  • brsbrs Posts: 33
    edited 2006-05-16 13:31
    Thanks Chip. I'll give it a shot tonight.

    Could you please explain the significance of declaring b[noparse][[/noparse]20] as a variable in the fido.spin file. why make this a permanent variable?
Sign In or Register to comment.