User manual

206
mikoBasic PRO for PIC32
MikroElektronika
This leads to equality of the following declarations:
dim ptr1 as ^const byteptr1 pointer in data space pointing to a byte in code space
const ptr1 as ^byteptr1 pointer in data space pointing to a byte in code space
Therefore, when declaring a pointer within constant declaration block, const qualier 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 dene 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, dene the procedural type
dim MyPtr as ^TMyFunctionType ‘ This is a pointer to previously dened type
dim sample as word
sub function Func1(dim p1, p2 as byte, dim p3 as word) as word Now, dene few functions
which will be pointed to. Make sure that parameters match the type denition
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 denition
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 denition
result = monday - yellow - rst
end sub
‘ main program:
main:
MyPtr = @Func1 ‘ MyPtr now points to Func1