Mikroelektronika MIKROE-742 데이터 시트

다운로드
페이지 532
POINTERS
A pointer is a data type which holds a memory address. While a variable accesses
that memory address directly, a pointer can be thought of as a reference to that
memory address.
To declare a pointer data type, add a carat prefix (
^
) before type. For example, in
order to create a pointer to an 
integer
, write:
^integer;
In order to access data at the pointer’s memory location, add a carat after the vari-
able name. For example, let’s declare variable p which points to a word, and then
assign value 5 to the pointed memory location:
var p : ^word;
...
p^ := 5;
A pointer can be assigned to another pointer. However, note that only the address,
not the value, is copied. Once you modify the data located at one pointer, the other
pointer, when dereferenced, also yields modified data.
Pointers to program memory space are declared using the 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]
P0 := ptr^;
ptr   := ptr + 3;   // ptr now points to b_array[3]
P0 := ptr^;
end.
Function Pointers
Function pointers are allowed in mikroPascal PRO for AVR. The example shows
how to define 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 finally how to call a function via pointer.
149
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Language Reference
mikroPASCAL PRO for AVR
CHAPTER 5