Start Back Next End
  
ZBasic Language Reference
86
ZBasic Microcontrollers
Example
Dim procTbl as IntegerVectorData({ @proc1, @proc2 })
Dim procAddr as UnsignedInteger
Declare Sub myProc() Based procAddr
#pragma CallTargets(myProc : procTbl, proc3)
If the CallTargets pragma occurs at the module level, it will be visible throughout the module.  If it
occurs within a procedure, it applies beginning at the line on which it occurs (overriding any
CallTargets pragma at the module level for the same based procedure) through the end of the
procedure or the next occurrence of a CallTargets pragma for the same based procedure.  A special
form of the CallTargets pragma, with no <procedure-list>, may be used to terminate the validity
of an earlier occurring CallTargets pragma.  This form is shown by example below.
#pragma CallTargets(myProc)
There is a special case where the compiler composes an implicit CallTargets list that may obviate the
need for explicitly specifying the CallTargets.  If a based procedure is defined where the base expression
is a simple expression comprising an initialized ProgMem data item with an index, the compiler assumes
that all of the elements of the ProgMem data item are call targets.
You may also specify a global call target list that will be visible from any module using the syntax below. 
The global call target list will be overridden by a non-global call target list present in a module or in a
procedure.
#pragma GlobalCallTargets ( <based-procedure> : <procedure-list> )
The effect of multiple call-targets pragmas for a given procedure is cumulative.
3.23 Reference Variables
Similar to the concept of a ByRef parameter for a subroutine or function, you may define a variable as a
reference.  A reference variable is interpreted as a “pointer to” the actual variable rather than the variable
itself.  Consequently, a reference variable is always the same size (typically 2 bytes) irrespective of the
size of the variable to which it refers.
A reference variable is defined in the same way as an ordinary variable but including the ByRef attribute
as illustrated in the examples below.  The second example illustrates a reference to an array of bytes.  As
with a procedure parameter that is an array, an array defined by reference is also single dimensioned with
a lower bound of 1.  Note that a reference variable, unlike other variables, cannot have an initialization
value specified in the definition.
Dim fval as Single ByRef
Dim buf() as Byte ByRef
The compiler dereferences a reference variable when it is used just as it does with ByRef parameters so
there are no extra syntactic elements required to perform dereferencing.  This begs the question,
however, of how the value of the reference gets set.  When a reference variable is defined, the content of
the space reserved for the reference is either uninitialized or set to zero depending on whether the
definition is local to a procedure or at the module level.  Since neither of these possible states is likely to
refer to any useful memory, you must set the value of the reference before any use of the reference
variable.  Initialzation of the reference is accomplished using the DataAddress property as illustrated
below.
Dim f as Single
Dim fval as Single ByRef
fval.DataAddress = f.DataAddress
Previous page Top Next page