Page 1 of 1

Strange Array Index Problem

PostPosted: 09 Aug 2011, 12:57
by Sonic
Hello,

i'm trying to indexing arrays with an ofset. But it doesn't work correct.

Code: Select all
Dim Tmp_byte As Byte
Dim Timer_index As Byte
Dim Timer_load As Byte
Dim Pwm_table(10) As Byte
Dim Timer_table(10) As Byte
...
Timer_index = 0
Tmp_byte = Timer_index + 1
Timer_load = Pwm_table(timer_table(tmp_byte))
Print Timer_load ; " ";
Timer_load = Pwm_table(timer_table(timer_index + 1))
Print Timer_load


Pwm_table and Timer_table are filled with valid values, but i got different results for Timer_load.
What's wrong?

Thanks in advance

(Bascom AVR 2.0.7.0)

Re: Strange Array Index Problem

PostPosted: 10 Aug 2011, 10:00
by deluca
Sonic wrote:Hello,

i'm trying to indexing arrays with an ofset. But it doesn't work correct.

Code: Select all
Dim Tmp_byte As Byte
Dim Timer_index As Byte
Dim Timer_load As Byte
Dim Pwm_table(10) As Byte
Dim Timer_table(10) As Byte
...
Timer_index = 0
Tmp_byte = Timer_index + 1
Timer_load = Pwm_table(timer_table(tmp_byte))
Print Timer_load ; " ";
Timer_load = Pwm_table(timer_table(timer_index + 1))
Print Timer_load


Pwm_table and Timer_table are filled with valid values, but i got different results for Timer_load.
What's wrong?

Thanks in advance

(Bascom AVR 2.0.7.0)


It may be that Bascom is having problems evaluating the index to an index:

Timer_load = Pwm_table(timer_table(timer_index+1))

Try rewriting this as

tmp_byte = timer_table(timer_index + 1)
Timer_load = Pwm_table(tmp_byt)

This is the same sort of problem that Bascom has with multiple term in an expression, like

a = b + c + d