64
Programming with TIDE
©2000-2008 Tibbo Technology Inc.
declare
function
multiply(a
as
integer
, b
as
integer
)
as
integer
dim
i
as
integer
i = multiply(
3
,
7
)
...
function
multiply(a
as
integer
, b
as
integer
)
as
integer
' now this
function doesn't have to be public.
multiply = a * b
end
function
Event handler subs require no declaration as they are already declared in your
device's platform.
No Recursion
One thing you have to know is that procedures cannot call themselves. Also, two
procedures cannot call each other. This is due to TiOS not using dynamic memory
allocation. Such allocation would create a serious overhead for the system, and
would drastically slow everything down -- not just recursive procedures. For more
information, see
Memory Allocation for Procedures
.
4.2.5.1
Passing Arguments to Procedures
When calling subroutines or functions, it is often necessary to pass a certain value
for processing within the procedure. An example of this would be a function which
calculates the sum of two values; naturally, such a function would need to get two
arguments -- the values which are to be added up.
There are two different ways to pass arguments to such a procedure:
The Default: Passing By Value
When passing an argument to a procedure by value, this argument is copied to a
location in memory which was reserved for the local variables of this function.
Processing is then done on this local copy -- the original remains untouched. For
example:
sub
foo(x
as
byte
)
...
x = 1
...
end
sub
sub bar
dim y as byte
y = 2
foo(y)
' at this point in code, y is still 2.
end sub
This way of passing variables is the default used in Tibbo Basic.
Passing By Reference
In certain cases, copying is not the preferred solution; for example, when a
procedure has to modify several arguments passed to it and these later have to be
66