Strange Array Index Problem

Sezione dedicata al sistema di sviluppo BASCOM-AVR per i micro AVR
At90s, Attiny, Atmega e Xmega

Strange Array Index Problem

Postby Sonic » 09 Aug 2011, 12:57

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)
Sonic
 
Posts: 2
Joined: 09 Aug 2011, 12:52

Re: Strange Array Index Problem

Postby deluca » 10 Aug 2011, 10:00

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
Ciao
Il mio sito: http://www.delucagiovanni.com ......e la chat: chat/
User avatar
deluca
Site Admin
 
Posts: 1104
Joined: 19 Jun 2011, 10:44
Location: 95123 - Catania (Italy)


Return to BASCOM-AVR

Who is online

Users browsing this forum: No registered users and 21 guests

cron