77
Dim persVar as Persistent Integer Based &H300
Dim progVar as ProgMem Single Based &H1000
BasicX Compatibility Note
Based variables are not available in BasicX compatibility mode.
3.23 Based Procedures
Like based variables, based procedures are a powerful tool intended to be used by advanced
programmers who fully understand their nuances. No actual code space is consumed by a based
procedure. Rather, declaring a based procedure simply tells the compiler how to generate an invocation
of the procedure once its address is known.
The syntax for declaring a based subroutine or based function is shown below.
Delare Sub <name> ( [<parameter-list>] ) Based <addr-expr>
Declare Function <name> ( [<parameter-list>] ) As <type> Based <addr-expr>
As with based variables, the <addr-expr> giving the address of the procedure to be invoked must have
an integral type and can be either constant or non-constant (i.e., computed at run time). The based
procedure declaration may be placed inside a subroutine or function in which case the declaration is
private to that routine. At the module level, the Declare keyword may be proceeded by Public or
Private and if neither is specified, the declaration will be public by default.
When using a based procedure, you must be very careful to be certain that the declaration matches the
actual procedure that exists at the address that is specified. If the address given is not the beginning of a
procedure that is the same type and has the same number and type of parameters, the result is
unpredictable but will likely cause your program to malfunction.
BasicX Compatibility Note
Based proceduresles are not available in BasicX compatibility mode.
3.24 Sub-byte Types
In addition to the fundamental data types described in Section 2.2, ZBasic also supports Bit and Nibble
data types. These are referred to as sub-byte types because they occupy less than a whole byte 1 bit
and 4 bits, respectively. In certain circumstances, these types may help reduce the total RAM usage of
an application. As compared to packing and unpacking bits in your source code, using these types will be
more efficient in both execution time and code space.
Bit and Nibble types may be used in most places where one of the fundamental data types may be
used. You can define arrays of them, you can define Bit and Nibble constants, you can pass them as
parameters and you can define functions returning these types. One limitation is that you cannot pass a
Bit or Nibble variable to a subroutine/function by reference unless the variable is byte-aligned (see
further discussion below). This implies, of course, that you may not be able to pass an array of sub-byte
types as a parameter since arrays are always passed by reference. The reason for this limitation is that
sub-byte variables do not necessarily begin on a byte boundary and there is no way for the called routine
to know what the alignment might be. One way to work around this limitation is to define an integral-byte
alias to the sub-byte type, pass the alias by reference and then define a new sub-byte alias in the called
routine. This works because integral-byte aliases are required to be byte aligned. Note that when
passed by value as a parameter, a sub-byte type parameter occupies an entire byte on the stack.