byte pointer memory access
David Betz
Posts: 14,516
I've been trying to write some simple SPIN code to access an array of bytes through a pointer and am having some trouble understanding the difference between the two methods of doing this. I've been trying to use the following code. It seems that test2 does what I expect but test1 does not. Shouldn't they be equivalent?
Thanks!
David
VAR
byte data[noparse][[/noparse]10]
long ptr
PUB init
ptr := @data
test1(2)
test2(3)
PUB test1(i)
ptr.byte := 1
PUB test2(i)
byte[noparse][[/noparse]ptr] := 1
Thanks!
David
VAR
byte data[noparse][[/noparse]10]
long ptr
PUB init
ptr := @data
test1(2)
test2(3)
PUB test1(i)
ptr.byte := 1
PUB test2(i)
byte[noparse][[/noparse]ptr] := 1
Comments
No they shouldn't.
ptr.byte is accessing the least significant byte of the actual pointer. Same as ptr.byte[noparse][[/noparse]0] would do.
byte[noparse][[/noparse]ptr] is accessing the byte that ptr is pointing to.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Help to build the Propeller wiki - propeller.wikispaces.com
Play Defender - Propeller version of the classic game
Prop Room Robotics - my web store for Roomba spare parts in the UK
Is it not this simple ?
var
byte data[noparse][[/noparse]10]
byte x
pub read_em_all | ptr
repeat 10
x := byte [noparse][[/noparse] @data ] [noparse][[/noparse] ptr++ ]
'do something with x
I can't even imagine what is going on here........."ptr.byte" , I will leave that to others
Ron
I have not the slightest idea what you are on to... You use an over-complex construction; and please note that ptr is NOT initialized to zero!!!!
X.BYTE[noparse][[/noparse]n] is someting you do with the "special registers" as
OUTA[noparse][[/noparse]8*n .. 8*n+7]
Post Edited (deSilva) : 12/24/2007 6:34:39 PM GMT
Another probably dumb question:
How do I continue a statement on a second line. For instance, I'd like to split up some of my method calls over several lines if they have a lot of parameters.
foo(a,b,c,d)
becomes
foo(
a,
b,
c,
d)
or something like that. Is this possible?
Not really aesthetic... But it comes handy for commenting things on that opportunity
Welcome to the land of indention-sensitive syntax!
Nick, not a friend of the above! No, really not!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Never use force, just go for a bigger hammer!
The DIY Digital-Readout for mills, lathes etc.:
YADRO