PDA

View Full Version : Array Question....please help



jmoskalski
- 30th October 2009, 20:03
Hi guys,

I have a problem that I am stuck at for hours. Here is some of my code:

temparray var word[3]
temparray.lowbyte[0]=%11100011
temparray.highbyte[0]=%00011100
lcdout $fe,$cf,"reis: ",ibin16 temparray[0]
pause 10000


The above works great, on my LCD I get 0001110011100011
but then, as my code progresses,

temparray.lowbyte[1] =%01010101
temparray.highbyte[1]=%11111111
lcdout $fe,$cf,"done: ",ibin16 temparray[0]


Now when my LCD changes, it displays 0101010111100011
My question is why does highbyte in array [0] get overwritten with the lowbyte from array[1]. I was expecting to get the first answer since I only changed temparray[1].

Can somebody please explain why this happened?

Acetronics2
- 30th October 2009, 20:42
Hi,

Don't you think


"temparray.highbyte[0]" and "temparray.lowbyte[1]" are one and same memory location ???

did you try



temparray.lowbyte[2] =%01010101
temparray.highbyte[2]=%11111111
lcdout $fe,$cf,"done: ",ibin16 temparray[1]


instead ...

Alain

mackrackit
- 30th October 2009, 21:17
Give this a read.
http://www.picbasic.co.uk/forum/showthread.php?t=544

jmoskalski
- 31st October 2009, 01:29
Thank you all for your help and for the link.
I was coming to the conclusion that user Acetronics mentioned but I just wasn't sure why. I'll follow the link above and get some info on word arrays.

Thank you Gentlemen for all your help.