Wednesday, September 27, 2023
A classic blunder, like getting involved in a land war in Asia
The first time I included some BASIC code,
I typed in the sample directly from a magazine
(like we used to do back in the 1980s).
The second
(and most recent) time I included BASIC code,
it was extracted from a disk image downloaded from the Intarwebs
(using code I wrote)
and then decoded into ASCII,
using code I wrote,
based off a text file I also found on the Intarwebs.
I didn't notice when I posted the code because it was
a wall of text 32 characters wide
(the width of the text screen on a Color Computer).
It was only months later when I finally noticed all the THENNOT
s littering the code.
There was nothing wrong with the actual file, but I did locate the bug in my code:
char const *const c_tokens[] = { "FOR", "GO", /* ... */ "SUB", "THEN" "NOT", "STEP", "OFF", /* ... */ "DSKO$", "DOS" };
If you look close,
you'll see there's a missing comma after the THEN
token,
and in C,
two literal strings separated by whitespace are concatenated into a single string.
Thus,
all the THENNOT
s I was seeing.
And a bunch of incorrect code because most of the BASIC keywords were then off-by-one
(a classic mistake of C programming).