User manual
210
mikoBasic PRO for PIC32
MikroElektronika
For example:
dim
a as byte[10] ‘ array a containing 10 elements of type byte
ptr as ^byte ‘ pointer 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 byte ‘ variables
ptr1 as ^byte ‘ pointers 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.
Structures
A structure represents a heterogeneous set of elements. Each element is called a member; the declaration of a structure
type species a name and type for each member. The syntax of a structure type declaration is
structure structname
dim member1 as type1
‘...
dim membern as typen
end structure
where structname is a valid identier, each type denotes a type, and each member is a valid identier. The scope
of a member identier is limited to the structure in which it occurs, so you don’t have to worry about naming conicts
between member identiers and other variables.