Shop OBEX P1 Docs P2 Docs Learn Events
How do you pass parameters to methods by using arrays? — Parallax Forums

How do you pass parameters to methods by using arrays?

ElectricAyeElectricAye Posts: 4,561
edited 2009-05-20 15:59 in Propeller 1
Hey everyone,

Let's say I declare an array of 6 elements made up of longs,
(Please note I used parentheses instead of brackets because my browser freaked out.)

LONG TemperatureArray(6)



Later in the Main program, I write values into my array, as follows:
TemperatureArray(0) := 0
TemperatureArray(1) := 10
TemperatureArray(2) := 20
TemperatureArray(3) := 30
TemperatureArray(4) := 40
TemperatureArray(5) := 50




Later in my Main program, I want to pass this array to a method via the method's parameter list and I use the technique lovingly known as "pass by reference," so I (think I) write the following:
MyBrilliantMethod (@TemperatureArray)




Next, down inside the code of MyBrilliantMethod, I want to extract the values that are stored in the addresses of the TemperatureArray. And here's where my ignorance begins to really balloon...
Would it - or could it - look like this???
PUB MyBrilliantMethod (HubMemoryAddressOfTempArray) | Temperature0, Temperature1, TemperatureEtc....

Temperature0 := LONG[noparse][[/noparse]HubMemoryAddressOfTempArray + AddressOffset0]
Temperature1 := LONG[noparse][[/noparse]HubMemoryAddressOfTempArray + AddressOffset1]
Temperature2 := LONG[noparse][[/noparse]HubMemoryAddressOfTempArray + AddressOffset2]
Temperature3 := LONG[noparse][[/noparse]HubMemoryAddressOfTempArray + AddressOffset3]
Temperature4 := LONG[noparse][[/noparse]HubMemoryAddressOfTempArray + AddressOffset4]
Temperature5 := LONG[noparse][[/noparse]HubMemoryAddressOfTempArray + AddressOffset5]




If this is a correct approach, then my next question is... What would be the correct value for the AddressOffsets? I presume AddressOffset0 would be zero. But what of the other offsets? How does an offset relate to the memory address?

many thanks for your help,
Mark

eyes.gif

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Watching the world pass me by, one photon at a time.

Post Edited (ElectricAye) : 5/20/2009 3:46:58 PM GMT

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-05-20 15:48
    Using the notation you've cited, each offset would be 4 more than the previous one. There's another, somewhat more convenient notation you can use:

    Temperature1 := LONG[noparse][[/noparse]HubMemoryAddressOfTempArray][noparse][[/noparse]Index]
    
    
    


    In this case, Index can increment by 1.

    -Phil
  • ElectricAyeElectricAye Posts: 4,561
    edited 2009-05-20 15:59
    Phil,
    that is GREAT! It's almost like I'm starting to really understand what all you gurus have been teaching me all these months. Thanks, too, for the tip on using the Index notation.

    bless you, Oh Pilgrim, bless you,

    Mark


    smile.gifsmile.gifsmile.gifsmile.gifsmile.gif
Sign In or Register to comment.