Mikroelektronika MIKROE-350 Data Sheet
' main program:
main:
MyPtr = @Func1 ' MyPtr now points to Func1
Sample = MyPtr^(1, 2, 3) ' Perform function call via pointer, call
Func1, the return value is 3
MyPtr = @Func2 ' MyPtr now points to Func2
Sample = MyPtr^(1, 2, 3) ' Perform function call via pointer, call
Func2, the return value is 5
MyPtr = @Func3 ' MyPtr now points to Func3
Sample = MyPtr^(1, 2, 3) ' Perform function call via pointer, call
Func3, the return value is 0
end.
end.
A function can return a complex type. Follow the example bellow to learn how to
declare and use a function which returns a complex type.
declare and use a function which returns a complex type.
Example:
This example shows how to declare a function which returns a complex type.
program Example
structure TCircle ' Structure
dim CenterX, CenterY as word
dim Radius as byte
dim Radius as byte
end structure
dim MyCircle as TCircle ' Global variable
sub function DefineCircle(dim x, y as word, dim r as byte) as TCircle
' DefineCircle function returns a Structure
' DefineCircle function returns a Structure
result.CenterX = x
result.CenterY = y
result.Radius = r
result.CenterY = y
result.Radius = r
end sub
main:
MyCircle = DefineCircle(100, 200, 30) ' Get
a Structure via function call
MyCircle.CenterX = DefineCircle(100, 200, 30).CenterX + 20 '
Access a Structure field via function call
' |------------------------| |-----|
' | |
' | |
' Function returns TCircle Access to one
field of TCircle
end.
end.
134
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Language Reference
mikroBasic PRO for AVR
CHAPTER 5