User manual

208
mikoPascal PRO for PIC32
MikroElektronika
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.
Note : Comparing pointers pointing to different objects/arrays can be performed at programmer’s own responsibility
a precise overview of data’s physical storage is required.
Pointer Addition
You can use Inc to add an integral value to a pointer. The result of addition is dened only if the pointer points to an
element of an array and if the result is a pointer pointing to the same array (or one element beyond it).
If a pointer is declared to point to type, adding an integral value n to the pointer increments the pointer value by n *
sizeof(type) as long as the pointer remains within the legal range (rst element to one beyond the last element). If
type has a size of 10 bytes, then adding 5 to a pointer to type advances the pointer 50 bytes in memory.
For example:
var
a : array[10] of byte; // array a containing 10 elements of type byte
ptr : ^byte; // pointer to byte
begin
ptr := @a[0]; // ptr is pointer to byte, pointing to a[0]
ptr := ptr + 3; // ptr+3 is a pointer pointing to a[3]
ptr^ := 6; // a[3] now equals 6
Inc(ptr); // ptr now points to the next element of array a: a[4]
end.
Also, you may sum values pointed to by pointers.
For example:
var
i, j, x : byte; // variables
ptr1 : ^byte; // pointers to byte
ptr2 : ^byte;
begin
i := 10; // assign value 10 to variable; i is at the address 0x0038