User manual
211
mikoPascal PRO for dsPIC30/33 and PIC24
MikroElektronika
For example:
var
a : array[10] of byte; // array a containing 10 elements of type byte
ptr : ^byte; // pointer to byte
begin
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:
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 0x0039
j := 5; // assign value 5 to variable; j is at the address 0x003A
ptr1 := @i; // ptr1 is a 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.
Records
A record (analogous to a structure in some languages) represents a heterogeneous set of elements. Each element is called a
eld. The declaration of the record type species a name and type for each eld. The syntax of a record type declaration is
type recordTypeName = record
eldList1 : type1;
...
eldListn : typen;
end;
where recordTypeName is a valid identier, each type denotes a type, and each eldList is a valid identier or a
comma-delimited list of identiers. The scope of a eld identier is limited to the record in which it occurs, so you don’t
have to worry about naming conicts between eld identiers and other variables.