All variables in the TE language are stored as null terminated character strings. Variables can be declared with lengths up to 255 characters long:
var a:255; // This is OK
var b:256; // illegal..
In fact an additional byte is set aside by the Telecom Engine to allow for the terminating null character, so a var of length 255 would take up 256 bytes.
Integer type variables are also stored as character strings and the TE language sets aside 22 bytes for each variable declared as type int (1 bytes for the sign, 20 bytes for the digits and one byte for the null terminator). Before assigning a value to a variable of type int the Telecom Engine will convert the assigned string to a numeric string value.
At the start of an application all var type variables are initialised to the blank string “” and all int type variables are initialised to 0.
The variables declared in the declaration_block before the main..endmain section are global variables that can be accessed by any function in the program (this applies to contants as well).
All variables declared inside functions are static variables that can only be accessed from within that particular function. The fact that these variables are static means that they will retain their values between function calls.
For example:
main
f();
f();
f();
endmain
func f()
int a;
a++;
applog("a=",a);
endfunc
Each time the function f() is called then the variable a is increased by one so by the third call a will have the value 3. If this behaviour is not what is required then it is up to the programmer to make sure all variables are initialised to the correct value at the top of each function.
Variables can be declared anywhere within a statement_block and can then be accessed from anywhere from that point on in the code to the end of the func..endfunc or main..endmain block. Variables declared within a function cannot have the same name as a function argument, global variable or global constant:
int a;
main
f("Hello");
end
func f(str)
var a:20; // illegal - same name as global
var str:10; // illegal - same name as function argument
endfunc
Different functions may declare variables of the same name so long as they don’t conflict with another variable, argument or constant that is in scope.