Shop OBEX P1 Docs P2 Docs Learn Events
Dereferencing Array Pointers — Parallax Forums

Dereferencing Array Pointers

Hey guys,
I have been passing array pointers like this:
byte payload[32]


nRF.TransmitPayload(@payload)

And then I can dereference it like this:
byte[payloadAddress][i]

So if I can do that, how come I cannot do this?
payload := byte[payloadAddress]

payload[2] := 1

What is the proper way of assigning the pointer to a variable so I can access the index without having to use the "byte" every single time?

Thanks and any help is greatly appreciated!

Comments

  • "payload := byte[payloadAddress]" says to get the byte value whose address is in "payloadAddress" and put the value in "payload"

    You can't give a name to a variable that contains an address in Spin like you can in C. Spin doesn't have the same kind of type name declarations as C. You have to use "byte[payloadAddress][2] := 1"
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2016-03-27 23:16
    In your third snippet, payload contains the value of the byte at payloadaddress. Setting payload[2] to 1, sets some other variable whose address is two payload widths away from payload.

    There really isn't any way to get away from the byte[...] nomenclature in Spin for accessing a remote byte variable whose address is known. That's just the way it's done.

    -Phil
  • Thanks for the pointers! Figured I would ask to see if there was a more elegant way of doing it. I will stick with the byte[]/word[]/long[] syntax
Sign In or Register to comment.