User manual
206
mikoBasic PRO for PIC32
MikroElektronika
This leads to equality of the following declarations:
dim ptr1 as ^const byte ‘ ptr1 pointer in data space pointing to a byte in code space
const ptr1 as ^byte ‘ ptr1 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 mikroBasic PRO for PIC32. The example shows how to dene and use a function
pointer:
Example:
Example demonstrates the usage of function pointers. It is shown how to declare a procedural type, a pointer to
function and nally how to call a function via pointer.
program Example;
typedef TMyFunctionType = sub function (dim param1, param2 as byte, dim param3 as word)
as word ‘ First, dene the procedural type
dim MyPtr as ^TMyFunctionType ‘ This is a pointer to previously dened type
dim sample as word
sub function Func1(dim p1, p2 as byte, dim p3 as word) as word ‘ Now, dene few functions
which will be pointed to. Make sure that parameters match the type denition
result = p1 and p2 or p3
end sub
sub function Func2(dim abc, def as byte, dim ghi as word) as word ‘ Another function of
the same kind. Make sure that parameters match the type denition
result = abc * def + ghi
end sub
sub function Func3(dim rst, yellow as byte, dim monday as word) as word ‘ Yet another
function. Make sure that parameters match the type denition
result = monday - yellow - rst
end sub
‘ main program:
main:
MyPtr = @Func1 ‘ MyPtr now points to Func1