Variables, Pointers, Constants, Scopes
|Top Previous Next|
Tibbo BASIC and Tibbo C support several simple variable types. These are signed and unsigned 8-, 16-, and 32-bit variables.
In addition, there is also a string type, which is unique to Tibbo BASIC and C.
Tibbo C supports static variables, while Tibbo BASIC does not.
Arrays and structures are supported in BASIC and C but the storage format in RAM differs between the two languages and there is no compatibility: you cannot pass an array or a structure from a BASIC procedure to a C function, or vice versa.
Tibbo C also supports unions. No surprises here.
Defining and declaring variables
All variables must be explicitly declared. Variables must be defined or declared before they are used.
Each variable has a fixed type and there are no "invariants" (variables that can change their type as needed).
Multi-variable definitions and declarations are OK, too.
The syntax of Tibbo BASIC doesn't allow you to initialize each variable in the multi-variable dim statement to the desired value.
C allows that:
In Tibbo BASIC and in Tibbo C there is no need to put all variable definitions on top of the procedure (function). You can mix "procedural" lines and new variable declarations and definitions:
Pointers (Tibbo C only)
Tibbo C supports pointers (and Tibbo BASIC doesn't).
Pointers are implemented in the standard manner, which is both the strength and the weakness of ANSI C.
Pointer arithmetic strengths are plentiful and well-known. I won't delve into compliments here.
The weakness is that C pointers are not safe. It's easy to wreck havoc with a poorly written pointer-wielding application.
Compared to Tibbo BASIC, which is a completely safe programming environment that won't allow bad code to corrupt application memory or TiOS, Tibbo C is an "almost safe" environment.
The "culprits" breaking the "safety record" of Tibbo C are pointers, arrays, structures, and unions.
One non-standard feature of Tibbo C that sets it apart from ANSI C is the string variable type.
The String Type and Pointers topic contains some interesting info on strings, as well as pointers to this unique variable type.