Mikroelektronika MIKROE-742 데이터 시트

다운로드
페이지 532
program Example;
type TMyFunctionType = function (param1, param2: byte; param3: word)
: word;  // First, define the procedural type
var
MyPtr: ^TMyFunctionType;
// This is a pointer to previously defined type
Sample: word;
function
Func1(p1, p2: byte; p3: word): word;// Now, define few
functions which will be pointed to. Make sure that parameters match
the type definition 
begin
result := p1 
and p2 or p3;                // return something
end;
function Func2(abc: byte; def: byte; ghi: word): word;     // Another
function of the same kind. Make sure that parameters match the type
definition  
begin
result := abc * def + ghi;                  // return something
end;
function Func3(first, yellow: byte; monday: word): word// Yet anoth-
er function. Make sure that parameters match the type definition   
begin
result := monday - yellow - first;          // return something
end;
//  main program:
begin
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.
@ Operator
The 
@
operator returns the address of a variable or routine, i.e. 
@
constructs a point-
er to its operand. The following rules are applied to 
@
:
- If X is a variable, 
@X
returns the address of 
X
- If 
F
is a routine (a function or procedure), 
@F
returns F’s entry point (the result is of 
longint
). 
150
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Language Reference
mikroPASCAL PRO for AVR
CHAPTER 5