49
TIDE and Tibbo BASIC User Manual
©2000-2008 Tibbo Technology Inc.
dim
i,k
as
word
dim d as dword
i=50000
d=60000
k=(i+d)/10
' result will be 11000. This is correct!
String and non-string variables cannot be mixed!
Yes, sorry, but you cannot do the following (compiler will generate
error):
'Wrong!!!
dim
x
as
byte
x=
5
+
"6"
In case you are wondering why x="6" would work but x=5+"6" doesn't: the latter
is a mixed expression in which the compiler cannot decide what is implied:
conversion of string to value and then addition, or conversion of value to string
and then string concatenation!
4.2.4.4
Compile-time Calculations
Tibbo Basic always tries to pre-calculate everything that can be pre-calculated
during compilation. For example, if you write the following code:
dim
x,y
as
byte
y=5
x=5+10+y
'compiler will precalculate 5+10 and then the Virtual Machine
will only have to do 15+y
Pre-calculation reduces program size and speeds up execution.
When processing a string like "x=50000" compiler first determines the variable of
what type would be necessary to hold the fixed value and chooses the smallest
sufficient variable type. For example, for 50000 it is, obviously, word. Next,
compiler applies the same rules of
as between two actual
variables. Hence, in our example this will be like performing byte= word.
One additional detail. Large fixed values assigned to variables of real type must be
written with fractional part, even if this fractional part is 0. Consider the following
example:
dim
r
as
real
r=12345678901
'try to compile this and you will get "constant too big"
error.
Compiler will notice that this constant does not fit even into dword and will
generate an error. Now, try this:
dim
r
as
real
r=12345678901.0
'that will work!
104
45