|
This is my attempt to save you some time by telling you my
experiences with tiny-c programs that weren't working.
1.
Early on I had trouble remembering that the source code of programs
written in tiny-c had to be linefeed delimited. This is no longer the
case because I figured out how to modify the tiny-c shell function
progin (gi) to strip out carriage returns from carriage return linefeed
delimited files. This is a good example of tiny-c's ability to enhance
itself. By the way, you can tell if a tiny-c program has carriage
returns in it when you load them because the number of bytes read and
the number of bytes loaded differ. These numbers are reported by the
shell command .r (which reads program source in).
tc>.r cb.tc
814
0 28 786 23714
tc>
The 814 is the number of bytes in cb.tc. The four
numbers on the next line are the current line number, number of lines,
number of bytes loaded and number of bytes still available. Notice that
814-786=28 (28 carriage returns got stripped).
2.
When you run tiny-c programs and then make changes with the shell's editor and
then use the shell's .w command to write out the new source code, if you
later use an external editor on the source, it looks like it has been
truncated! This is due to the fact that the interpreter replaces the
trailing quotes in character strings with nulls. External editors just
drop everything after these nulls. This fact led me to write the tiny-c
program ntq.tc to
turn nulls into quotes just so I could once again use my external
editor.
3.
There are important differences between the (currently) three different
versions of tiny-c. The CP/M version does not support the for statement
or the unary operators ++, -- and !. The PC/DOS version uses
16-bit integers. The Linux version uses 32-bit integers. This means, for example, that the tiny-c program crypt.tc won't work
in the PC/DOS version, because it does things like
z=10000*m+1000*o+100*n+10*e+y
and if m is, say, 5, the 16-bit integers can't handle 50000.
The largest 16-bit integer is 32767. The largest 32-bit integer is 2147483647.
The binary tree sort program (tree.ipl) reveals other things you have to worry about from version
to version. Interpreter sizing constants which control how big program
source code can be etc. and this 16-bit (2-byte) / 32-bit (4-byte)
integer issue play a role here.
4.
Hard-to-remember "weirdnesses" remain in the interpreters which involve
the need to put code on separate lines, not on a single line. It's best
to keep it simple and write if-else, for and while statements like so:
if ( ) [
blah
]
else [
blah
]
for ( ) [
blah
]
while ( ) [
blah
]
Also, don't put a comment or an extra blank line at the tail end of your
tiny-c programs! They may not work if you do! Trust me.
5.
Case matters. Like C, case matters in tiny-c. It's best to use lowercase
function and variable names. Porting tiny-c programs
from PC/DOS to Linux often involves lowercasing filenames as well.
6.
The only way to learn tiny-c is to write programs in it! Here's a good one to try.
Write a program in tiny-c that prints out the multiplication tables from 1*1 to 12*12.
tc>.r mult.tc
271
0 16 271 89729
tc>.mult
mult.tc - 1/10/9 - lrb
Press Enter ...
1 * 1 = 1
1 * 2 = 2
1 * 3 = 3
1 * 4 = 4
1 * 5 = 5
1 * 6 = 6
1 * 7 = 7
1 * 8 = 8
1 * 9 = 9
1 * 10 = 10
1 * 11 = 11
1 * 12 = 12
Press Enter ...
2 * 1 = 2
2 * 2 = 4
2 * 3 = 6
2 * 4 = 8
2 * 5 = 10
2 * 6 = 12
2 * 7 = 14
2 * 8 = 16
2 * 9 = 18
2 * 10 = 20
2 * 11 = 22
2 * 12 = 24
Press Enter ...
Here's how I did it.
This runs under the tiny-c shell: mult.tc
This runs as a standalone: mult.ipl
Have fun!
TcT ("Tiny-c Tim")
|