04-09-2010, 07:04 AM
programandala.net Wrote:Hi all,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 -->
I'm working on my first port from Sinclair Basic to ZX Basic. I'm excited about it. I'd love to program compiled versions of some old programs of mine, but first I need to acquaint with this wonderful and impressive tool.
I'm using ZX Basic 1.2.0 under Debian GNU/Linux.
Quote: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):Code:dim b2 as ubyte
for b2=0 TO 255
print at 2,0;"b2=";b2;" "
next b2
border 4
print "This message never will be printed"
pause 0
I found the problem because I needed a loop from 0 to 255, so I used the ubyte data type for the index variable. Then I realized the loop repeated forever!
[...]
Do you think this is a language feature or a compiler bug?![]()
Code:
unsigned char b2;
for (b2 = 0; b2 <= 255; b2++) {
...
}
Code:
DIM b2 As Ubyte = 0;
DO
LET b2 = b2 + 1
...
LOOP UNTIL b2 = 0