Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
for-next repeats forever because of data type limit
#3
boriel Wrote:First of all, 1.2.0 is *VERY* old and might have lot of bugs. Please, download 1.2.5 or 1.2.6-beta here: <!-- m --><a class="postlink" href="http://www.boriel.com/files/zxb/">http://www.boriel.com/files/zxb/</a><!-- m -->

Done. I installed 1.2.0 some months ago, and I forgot to upgrade.

boriel Wrote:Unfortunately, it's a feature. :| This is something already discused: you're iterating a loop 256 times using a byte counter. It's really hard to do this, even in assembler, because you loop over the entire counter range (256), so the count will always overflow. The FOR sentence in basic is very powerful, it's equivalent to the following C code (if you don't know C, it does not matter):

Thank you for the explanation. I understand. But at first sight I supposed it would work, because the index values were in range (0-255) for ubyte. You're right, that means 256 iterations, but that's the range a ubyte can hold: from 0 to 255. I supposed the compile time action of NEXT would be to check if the limit (255) had been reached, and don't loop again if so. But it seems it first increases the index. I think the current behaviour is less logical.

Anyway, it's not an important! I just wanted to confirm the issue.

I'll check what FreeBASIC does in such cases.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)