User manual
207
mikoPascal PRO for dsPIC30/33 and PIC24
MikroElektronika
Pointers and memory spaces
Pointers can point to data in any available memory space.
Pointers can reside in any available memory space except in program (code) memory space.
var ptr1: ^const byte; // ptr1 pointer in data space pointing to a byte in code space
var ptr2: ^const ^volatile sfr byte; rx; // ptr2 is pointer in rx space pointing to a
pointer in code space pointing to volatile byte in sfr space
var ptr3: ^data byte; code; // error, pointers can not be placed in code space
Due to backward compatibility, pointers to program memory space can also be declared within constant declaration
block (using keyword const):
program const_ptr;
// constant array will be stored in program memory
const b_array: array[5] of byte = (1,2,3,4,5);
const ptr: ^byte; // ptr is pointer to program memory space
begin
ptr := @b_array; // ptr now points to b_array[0]
PORTA := ptr^;
ptr := ptr + 3; // ptr now points to b_array[3]
PORTA := ptr^;
end.
This leads to equality of the following declarations:
var ptr1 : ^const byte; // ptr1 pointer in data space pointing to a byte in code
space
const ptr2 : ^byte; // ptr2 pointer in data space pointing to a byte in code space
Therefore, when declaring a pointer within constant declaration block, const qualier refers to pointed object, not to
pointer itself.
Notes:
- Pointer to constant space (Flash memory) is allocated in RAM.
- Constants of a simple type are not allocated in the Flash memory nor in RAM, but changed in the compile time, and
therefore address of a such constant can not be obtained.
Function Pointers
Function pointers are allowed in mikroPascal PRO for dsPIC30/33 and PIC24. The example shows how to dene and
use a function pointer: