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

Passing Arrays

G.BraverG.Braver Posts: 3
edited 2006-12-18 21:54 in Propeller 1
Could someone provide the proper syntax for passing an array by reference to a spin function, and then reading and writing the array elements from that function.

For Example:

VAR
· LONG Array[noparse][[/noparse]100]

PUB ArrayTotal(ptr_array, size)| index, sum

··sum :- 0
· REPEAT index FROM 0 TO (size-1)
··· sum += LONG[noparse][[/noparse]ptr_array][noparse][[/noparse]index]·· ' This syntax seems to provide strange results in some situations, but so does LONG[noparse][[/noparse]ptr_array+index]
· RESULT := sum

Questions:

1.· Is this the proper syntax for addressing in this type of situation?
2.· Can the [noparse]/noparse brackets of the LONG instruction contain expressions, such as LONG[noparse][[/noparse]ptr_array][noparse][[/noparse]index-1]?

Thanks in advance for the help.


·

Comments

  • rokickirokicki Posts: 1,000
    edited 2006-12-18 21:54
    Yes, that's correct, on both counts.

    To call, use ArrayTotal(@Array, 100)

    LONG[noparse][[/noparse]a][noparse][[/noparse]c] is identical to LONG[noparse][[/noparse]a+4*c] (except they use different bytecodes
    and LONG[noparse][[/noparse]a][noparse][[/noparse]c] is shorter and probably a bit faster.)

    BYTE[noparse][[/noparse]a][noparse][[/noparse]c] is identical to BYTE[noparse][[/noparse]a+c] (with the exceptions given above).

    Note that Long[noparse][[/noparse]a][noparse][[/noparse]0] is always the same as Long[noparse][[/noparse]a].

    Tell us more about the strange results you are seeing.
Sign In or Register to comment.