Mikroelektronika MIKROE-350 Fiche De Données

Page de 526
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, if you
are creating a pointer to an 
integer
, you would write:
^integer
To access the data at the pointer’s memory location, you add a carat after the vari-
able name. For example, let’s declare variable p which points to 
word
, and then
assign the pointed memory location value 5:
dim as ^word
'...
p^ = 5
A pointer can be assigned to another pointer. However, note that only address, not
value, is copied. Once you modify the data located at one pointer, the other pointer,
when dereferenced, also yields modified data.
@ Operator
The @ operator returns the address of a variable or routine, i.e.
@
constructs a
pointer 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
). 
140
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Language Reference
mikroBasic PRO for AVR
CHAPTER 5