User manual

212
mikoBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
For example:
dim
a as byte[10] ‘ array a containing 10 elements of type byte
ptr as ^bytepointer to byte
main:
ptr = @a[6] ‘ ptr is pointer to byte, pointing to a[6]
ptr = ptr - 3 ‘ ptr-3 is a pointer pointing to a[3]
ptr^ = 6 a[3] now equals 6
Dec(ptr) ‘ ptr now points to the previous element of array a: a[2]
end.
Also, you may subtract two pointers. The difference will be equal to the distance between two pointed addresses, and
is calculated regarding to the type which the pointer points to.
For example:
dim
i, j, x as bytevariables
ptr1 as ^bytepointers to byte
ptr2 as ^byte
main:
i = 10 ‘ assign value 10 to variable; i is at the address 0x0039
j = 5 ‘ assign value 5 to variable; j is at the address 0x003A
ptr1 = @i ‘ ptr1 is pointer to byte, pointing to i
ptr2 = @j ‘ ptr2 is a pointer pointing to j
x = ptr2 - ptr1 result is equal to the distance between the two pointed addresses;
x = 1 (1 byte)
x = ptr1^ - ptr2^ ‘ result is equal to the difference of the values pointed to; x = 5
end.