another beautiful BUG in FreeBAsic is the following:
' when ADDR is declared as UShort the loop from 0x0000 to 0xFFFF is infinite (once ADDR arrive to 0xFFFF does not stops but reinitiate from 0x0000)
'when ADDR is declared UByte the loop from 0x00 to 0xFF is infinite (once ADDR reaches 0xFF it will newly begin from 0x00)
dim as ubyte RAM(&HFFFF)
for ADDR as ushort = &H0000 to &HFFFF
RAM(ADDR) = cubyte(100*rnd()) ' fill the ram with some random values
print ADDR,RAM(ADDR)
next ADDR
the loop WILL NEVER ENDS
to avoid the error one have to declare ADDR as integer:
for ADDR as integer = &H0000 to MAX_RAM
next ADDR
Compiler malfunction?? Error with variable declarations/cycles
-
- Posts: 18
- Joined: May 31, 2008 9:54
Re: Compiler malfunction?? Error with variable declarations/cycles
Topic discussed many times on the forum!
At each loop, the comparision is executed after the incrementation.
With an ushort, the test 'ADDR > &HFFFF' will be never verified.
At each loop, the comparision is executed after the incrementation.
With an ushort, the test 'ADDR > &HFFFF' will be never verified.