Since this is the beginners thread there are a couple of things I would like to say:
In your example you have defined the array
This defines an array of 129
elements, 0 to 128. In your code, your loop skips element at index 0.
Freebasic allows you to better define an array stating both its lower bounds and its upper bounds as Mr Swiss shows you:
Code: Select all
Dim Buf(1 To 128) as Ubyte ' corrected definition
The iterator variable A is a signed byte variable with a limit of 127. In binary 127 is 0111 1111. If you add 1 to 127 you get 128, binary 1000 0000. With a signed variable however the left most bit inicates the sign (1 for negative, 0 for positive), so instead of 128 you get -128 (2's compliment arithmatic).
So when the loop tests the iterator after 127, it sees -128 and continues on.
Fxm is using the -exx compiler option which adds array bounds checking and produces a runtime error.