Mikroelektronika MIKROE-724 データシート
210
mikoBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
program example
dim w as word
ptr_b as ^byte
ptr_arr as ^byte[10]
arr as byte[10]
main:
ptr_b = @arr ‘ @ operator will return ^byte
w = @arr ‘ @ operator will return ^byte
ptr_arr = @arr ‘ @ operator will return ^byte[10]
end.
If
F
is a routine (a function or procedure),
@F
returns a pointer to
F
.
Related topics: Pointer Arithmetic
Pointer Arithmetic
Pointer arithmetic in the mikroBasic PRO for dsPIC30/33 and PIC24 is limited to:
- assigning one pointer to another,
- comparing two pointers,
- comparing pointer to zero,
- adding/subtracting pointer and an integer value,
- subtracting two pointers.
Assignment and Comparison
The simple assignment operator (=) can be used to assign value of one pointer to another if they are of the same type.
Assigning the integer constant 0 to a pointer assigns a null pointer value to it.
Two pointers pointing to the same array may be compared by using relational operators
=, <>, <, <=, >,
and
>=
.
Results of these operations are the same as if they were used on subscript values of array elements in question:
dim ptr1 as ^byte
ptr2 as ^byte
a as byte[10] ‘ array a containing 10 elements of type byte
main:
ptr1 = @a[4]
ptr2 = @a[2]
if (ptr1 = ptr2) then ... ‘ won’t be executed as 4 is not equal to 2
if (ptr1 > ptr2) then ... ‘ will be executed as 4 is greater than 2
if (ptr1^ = ptr2^) then ... ‘ if the value pointed to by ptr1 is equal to the value
pointed to by ptr2 ...
if (ptr1^ > ptr2^) then ... ‘ if the value pointed to by ptr1 is greater to the value
pointed to by ptr2 ...
end.