User manual
209
mikoPascal PRO for dsPIC30/33 and PIC24
MikroElektronika
program example;
var w : word;
ptr_b : ^byte;
ptr_arr : ^array[10] of byte;
arr : array[10] of byte;
begin
ptr_b := @arr; // @ operator will return ^byte
w := @arr; // @ operator will return ^byte
ptr_arr := @arr; // @ operator will return ^array[10] of byte
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 mikroPascal 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:
var ptr1 : ^byte;
ptr2 : ^byte;
a : array[10] of byte; // array a containing 10 elements of type byte
begin
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.