|Top Previous Next|
There are two types of scopes: global and local.
The global scope
Every source file (.TBS or .TC), as well as every HTML file (.HTML) with Tibbo BASIC or C code in it, contains within itself one global scope.
A variable defined outside of any procedure is considered to be within this global scope and is called a global variable.
A global variable of one source file cannot be used in another source file unless this variable is declared there:
Such declarations are usually placed in header files — .TPH for Tibbo BASIC and .TH for Tibbo C.
Header files must be included into your source code file:
Despite what's just been said, global variables must have unique names throughout your project. Defining two global variables with the same name in two different files will generate a linker error... with the following exception:
In Tibbo C, you can define multiple static global variables with the same name in different files. The same is not possible in Tibbo BASIC because it doesn't support the static storage class specifier.
There is no cross-checking of variable types between files. You could define f as a word type in one file and then declare it as a string type in another file and TIDE would not notice! Be very careful with this!
Every procedure of BASIC and C has its own local scope.
The special feature of Tibbo BASIC and Tibbo C is that in addition there are even smaller local (and nesting) scopes within control structures.
Think of it this way: anywhere execution forks (or loops), there are as many sub-scopes as there are possible paths the execution can take.
Local variables and other entities can be defined on any scope's level!
A local variable (or other entity) takes precedence over all variables (as well as procedure names and other entities) with the same name that are defined at outer (higher) scopes.
Here is a C example of code that declares a variable f in every possible scope. There are 7 of them here!
Scopes in HTML
The peculiarity of HTML files is that BASIC/C code inside is not arranged into procedures. The entire HTML file is like one large procedure.
Therefore, procedure-level scope doesn't exist in HTML files. Control structures still have sub-scopes.
Here is one HTML example (the rules of putting code in HTML files are explained in Working with HTML):