Cross-Calling Tibbo BASIC and C Procedures
It is possible to call Tibbo BASIC subs and functions from Tibbo C and Tibbo C functions from Tibbo BASIC. We refer to this as "cross-calling."
As Tibbo BASIC arrays and structures are not compatible with the arrays and structures of Tibbo C, it is not possible to cross-call procedures that have array or structure arguments or return the same.
There is no cross-checking of argument and return value types. You could define f as a word argument in the BASIC declaration, while having it as a string type in the C implementation, or vice versa. TIDE will not be able to catch such a discrepancy. Be very careful with this!
The following table will help you with cross-calling — it puts together the corresponding language elements of Tibbo BASIC and C:
Tibbo BASIC |
Tibbo C |
Subs and functions |
|
sub name() end sub |
void name(){ } |
function name() as simple_type end function |
simple_type name(){ } |
Argument passing: |
|
sub name(x as simple_type)... |
void name(simple_type x)... |
sub name(ByVal x as simple_type)... |
void name(simple_type x)... |
sub name(ByRef x as simple_type) |
void name(simple_type *x)... |
Here is an example of calling two C functions from BASIC:
declare function c_increment(x as byte) as byte declare sub c_str_double(byref s as string) 'notice how byref becomes * on C side sub on_sys_init dim x as byte=5 x=c_increment(x) 'x will be 6 dim s as string="TIBBO" c_str_double(s) 's will be "TIBBOTIBBO" end sub
unsigned char c_increment(unsigned char x){ return ++x; } void c_str_double(string *s){ *s=*s+*s; }
The same, but the other way around — C calls a function and a sub in BASIC:
function basic_increment(x as byte) as byte basic_increment=x+1 end function sub basic_str_double(byref s as string) s=s+s end sub
unsigned char basic_increment(unsigned char x); void basic_str_double(string *s); void on_sys_init(){ unsigned char x=5; x=basic_increment(x); string s="TIBBO"; basic_str_double(&s); }