{"id":204,"date":"2026-06-30T13:37:47","date_gmt":"2026-06-30T13:37:47","guid":{"rendered":"https:\/\/permacomputer.solarpunk.au\/?p=204"},"modified":"2026-06-30T13:37:47","modified_gmt":"2026-06-30T13:37:47","slug":"tiny-c-reference-manual-excerpt","status":"publish","type":"post","link":"https:\/\/permacomputer.solarpunk.au\/?p=204","title":{"rendered":"tiny-c Reference Manual Excerpt"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><em>The project found this little manual instructive. You could say it is a kind of C flavour that is inspired by BASIC!<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/archive.org\/details\/tiny-c_manual\">https:\/\/archive.org\/details\/tiny-c_manual<\/a><\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Preface<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">The sources of ideas that went into tiny-c are many. First there is BASIC [Kemeny &amp; Kurtz 1967]. BASIC has become the de facto standard training language in the United States. It industry, is popular in high schools, universities, even in where it is used for some production work. Although BASIC has its faults, its one big strength is that it is easy to learn. This is largely because it offers a single computing environment. You can enter new program lines, change old ones, and start a program running all from one command environment. You do not have to remember the environment you are in, i.e., you edit mode, compile mode, link mode, system mode, run mode, etc., when giving a command. There are no commands to shift from mode to mode. There no relocatable object modules, link editors, and all the other paraphernalia of \u201creal\u201d computers. Is is very simple and very adequate. Thus a focus is made on the essential elements of computing, as opposed to the elements of \u201cwrestling\u201d with a computer.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The LOGO language [Feurzeig 1975] is in many ways similar to tiny-c.\u00a0It offers a well-structured language based on BASIC, as well as a single environment for programming and execution. LOGO was used experimentally in public schools with very young children. The experiment showed that children could grasp simple computer concepts and work through a prepared set of exercises, and then do creative work of their own.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">C [Ritchie, Kernighan, &amp; Lesk 1975] is a computer language designed by Dennis Ritchie, at Bell Telephone Laboratories, tiny-c borrows its overall structure from C. C is broadly used in universities and in industry. It has been used to program a very advanced and powerful computer operating system, called UNIX [Ritchie &amp; Thompson 1974]. At yet it is a very simple language. C has no native input\/output, e.g., read or print statements. Input\/output is done using functions. Thus C concentrates on COMPUTING facilities, and allows external development or elaborations of input\/output. tiny-c has adopted this idea.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The command environment for tiny-c is written in tiny-c.&nbsp;It needs no translation to the micro-processor\u2019s machine language. This corresponds somewhat to the idea of using C as the programming language to implement UNIX. So, although intended as a training language for structured programming, tiny-c is a powerful language.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The tiny-c OWNER\u2019S MANUAL is trying to reach four audiences at the same time. For those new to structured programming we have a brief tutorial and program walk-through so they can get the gist of it without getting bogged down in details. Experienced users of structured programming will find that the references sections let them quickly discover the features of tiny-c.&nbsp;For those who want to know how the tiny-c interpreter works, we have described its operation. And, finally, for those who want to install tiny-c on their home computer, we have included a complete installation guide.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Introduction<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">What is tiny-c? tiny-c is<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>a language, plus<\/li>\n\n\n\n<li>a standard library, plus<\/li>\n\n\n\n<li>a program preparation system.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Without any other software aids, you can prepare tiny-c programs, run them, edit them, store them on a cassette or floppy disk, and read them back later.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">tiny-c is a structured programming language which has if-then-else, while-loops, functions, global and local variables, and character and integer data types, pointers, and arrays.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">tiny-c is independent of operating systems. You can interface it easily to the input\/output routines on your computer.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">tiny-c can invoke your own machine language subroutines so the tiny-c programming language can be fitted to your system and your system can be reflected in and extend the language.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">A tiny-c Program Walk-Through<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Figure 1-1 is a complete tiny-c program consisting of two functions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">FIGURE 1-1<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>\/* guess a number between 1 and 100\n\/* T. A. Gibson, 11\/29\/76\n\nguessnum &#91;\n    int guess, number\n    number = random (1,100)\n    pl \"guess a number between 1 and 100\"\n    pl \"type in your guess now\"\n    while (guess != number) &#91;\n        guess = gn\n        if (guess == number) pl \"right !!\"\n        if (guess &gt; number) pl \"too high\"\n        if (guess &lt; number) pl \"too low\"\n        pl\"\"; pl\"\"\n    ] \/* end of game loop\n]     \/* end of program\n\n\/*\n\/* random-generates a random number\n\nint seed, last \/* globals used by random\nrandom int little, big &#91;\n    int range\n    if (seed == 0) seed = last = 99\n    range = big - little + 1\n    last = last * seed\n    if (last &lt; 0) last = -last\n    return little + (last\/8) % range\n]<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">End of FIGURE 1-1<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">How does this program work? Let\u2019s do a program walk-through:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Starting at the top, the first two lines are COMMENTS. A comment start with <code>\/*<\/code> and goes to the end of the line.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u201c<code>guessnum<\/code>\u201d is the name of a FUNCTION which is called to start the program.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Following \u201c<code>guessnum<\/code>\u201d is a COMPOUND STATEMENT, which is 12 lines long, the last line being:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>]     \/* end of program<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A compound statement is everything between balanced left-right brackets.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The first SIMPLE STATEMENT in <code>guessnum<\/code> is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int guess, number<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This declares two INTEGER VARIABLES named \u201c<code>guess<\/code>\u201d and \u201c<code>number<\/code>\u201d. All variables in tiny-c must be declared. When executed, the <code>int<\/code> statement will create the variables, and given them an initial value of zero.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The second simple statement in <code>guessnum<\/code> is<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>number = random (1,100)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This sets <code>number<\/code> equal to the value of the tiny-c program function <code>random<\/code> executed with its first ARGUMENT equal to 1 and its second argument equal to 100. In our program the function random returns a random number between 1 and 100.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On the next line, <code>pl<\/code> is a tiny-c LIBRARY FUNCTION which prints a line. In prints the quoted string which is its argument.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>while<\/code> sets up a LOOP. The general form of <code>while<\/code> is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>while (expression) statement<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In this instance, the EXPRESSION part is<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>guess != number<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">where <code>!=<\/code> means not equal to. This expression is evaluated, and if it is true, the statement is done, and then the expression is evaluated again. If it is false, the statement is skipped. Initially, <code>guess<\/code> is 0 and <code>number<\/code> cannot be less than `, so the expression is initially true. Therefore the statement is executed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The statement is compound, and is composed of six simple statements. The first of these statements is<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>guess = gn<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>gn<\/code>, which stands for \u201cget number\u201d is another standard library function. It reads a number types in by the user at the terminal, and returns that value. So here the program waits until the user types a number and a carriage return, and then guess is assigned the number typed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The next three simple statements are <code>if<\/code> statements. The general form of the <code>if<\/code> statement used here is<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (expression) statement<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">where statement is executed if the expression is true.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Statements five and six of the <code>while<\/code>\u2019s compound statement are <code>pl\"\"<\/code>. <code>pl\"\"<\/code> goes to a new line, and prints nothing. The semicolon allows you to write more than one simple statement on the same program line. So<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pl\"\" ; pl\"\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">prints two blank lines.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now we are at the end of the <code>while<\/code> loop. Since the expression part of the <code>while<\/code> was true, the <code>while<\/code> statement is executed again. This starts with another evaluation of the expression to see if it is true or false. If the first guess is not equal to <code>number<\/code>, the compound statement is executed again. Another guess is read, the appropriate remark is made, and two more blank lines are printed; the <code>while<\/code> is done yet again. Eventually, the user gets the right number and <code>guess<\/code> is equal to <code>number<\/code>. This will cause a \u201cright!!\u201d and two blank lines to be printed. The while condition is then tested again. The expression <code>guess != number<\/code> is evaluated and found to be false, so the entire compound statement of the <code>while<\/code> is skipped, which brings us to the end of <code>guessnum<\/code>. The game is over. The program stops because the end (the last <code>]<\/code>) of <code>guessnum<\/code> is reached.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Before we walk through <code>random<\/code>, notice the integers <code>seed<\/code> and <code>last<\/code> are declared outside of both <code>guessnum<\/code> and <code>random<\/code>. They are called GLOBAL VARIABLES. They will be created once when the program is started. They are initially zero, and are known and usable by both <code>guessnum<\/code> and <code>random<\/code>. On the other hand, <code>guess<\/code>, <code>number<\/code>, and <code>range<\/code> are LOCAL VARIABLES. <code>guess<\/code> and <code>number<\/code> are known and usable only within <code>guessnum<\/code>, while <code>range<\/code> is local to <code>random<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The first line of <code>random<\/code> gives the function name. And, before the <code>[<\/code>, it declares two integer arguments, <code>little<\/code> and <code>big<\/code>. A VALUE must be supplied for each argument when a function is called. The call in the sixth line of <code>guessnum<\/code> sets <code>little<\/code> to 1, and <code>big<\/code> to 100. Now we enter the BODY of the function <code>random<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>range<\/code> is declared an integer and is initially zero. On the first call, <code>seed<\/code> is zero. Now <code>seed<\/code> and <code>last<\/code> are both set to 99. <code>range<\/code> is calculated, and is 100. <code>last<\/code> is set to the product of the <code>last<\/code> and <code>seed<\/code> which is 9801. This is not less than 0, so the statement part of the <code>if<\/code> is not evaluated.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We next come to the <code>return<\/code> statement. It does two things. First, it evaluates the expression. The result is made the VALUE OF THE FUNCTION. Second, it returns control to the program that called the function. tiny-c expressions are similar to algebraic expressions. The symbol <code>+<\/code> means add, <code>\/<\/code> means divide, and <code>-<\/code> means subtract (or take the negative). To indicate multiplication, a <code>*<\/code> is used. An unusual symbol is <code>%<\/code>, which means divide the left side by the right side and take the REMAINDER (not the quotient). So, for example,<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1225 % 100<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">is 25.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thus the return statement calculates the expression:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>little + (last\/8) % range\n\n= 1 + (9801\/8) remainder 100\n\n= 1 + 1225 remainder 100\n\n= 1 + 25\n\n= 26<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The value 26 is returned as the value of function <code>random<\/code>. It also leaves 9801 in <code>last<\/code>, and 99 in <code>seed<\/code>. Since these are global variables, their values are retained between function calls. This is not true of local variables like <code>range<\/code>. Their values are retained only during the execution of the function in which they are defined. When that function is left their values are lost.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On a second call to <code>random<\/code>, <code>range<\/code> is recreated, and reinitialised to zero. <code>seed<\/code> is not zero, so <code>seed<\/code> and <code>last<\/code> are not set to 99, but remain 99 and 9801 respectively. <code>range<\/code> is recalculated as 100. Then<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>last = last * seed\n\n     = 9801 * 99\n     \n     = 970299<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This number is too big for tiny-c.&nbsp;Any computer has a limit on the size of the numbers that can be computed. tiny-c numbers must be in the range<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-32768 &lt;= number &lt;= 32767.<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>last<\/code> OVERFLOWS this range. It will be assigned the value -12741! (We explain this more completely in Section 2.11.) This is less than 0, so the next statement assigns <code>last<\/code> the value 12741. Then the return statement calculates:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  1 + (12741\/8) remainder 100\n\n= 1 + 1592 remainder 100\n\n= 93<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This is returned as the second value of <code>random<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">REVIEW OF THE WALK-THROUGH<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The purpose of the walk-through is to get a feeling for programming in tiny-c.&nbsp;We have seen that<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A tiny-c program is a set of functions.<\/li>\n\n\n\n<li>Some functions are standard library functions, line <code>gn<\/code> and <code>pl<\/code>.<\/li>\n\n\n\n<li>Global variables stay around and hold their values. Local variables come and go.<\/li>\n\n\n\n<li>Function and variable names can be as long as you want.<\/li>\n\n\n\n<li>A group of statements enclosed in brackets makes a compound statement which can be treated just like a simple statement.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Structured Programming \u2013 What tiny-c Is All About<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Perhaps you have heard structured programming described as \u201cgo-to-less\u201d programming. Or programming with just <code>if-then-else<\/code> and <code>do-while<\/code> control statements. Such remarks oversimplify what structured programming is all about. The essence of structured programming is PROGRAM CLARITY. You can write programs in small, modular parts, with easy-to-follow program flow. You can use well-chosen, descriptive variable names. This leads to clear, understandable programs. Program clarity is what structured programming is all about.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We discuss here four principle ideas that make program clarity possible. These are: modularity, predictable program flow, local variables, and the simple idea of meaningful variable names.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">MODULARITY in software is just as important as modularity in hardware. It makes it humanly possible to deal with complexity. A module is a brick or atom used for building bigger modules. Seen from within, a module may be very complex but from the outside it is an indivisible whole. Software modularity is achieved through the use of FUNCTIONS.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">PROGRAM FLOW is predictable if you can point to any statement and easily answer the question \u201cunder what conditions is this statement executed?\u201d This is particularly important if the program is 20 or 30 pages long, and still has bugs. Scanning the whole program and drawing arrows is no fair. That\u2019s not considered an easy way to answer the question. Predictable program flow can be achieved in many ways. In tiny-c, it is done with COMPOUND STATEMENTS.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Compound Statements<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Functions also make it possible to hide variables used in a strictly local context. The variable n is very popular; it\u2019s used frequently to count things. Have you ever had a program blow up because you were using n in two places for two purposes? The fix was to change one of them to n1. A better idea is in the concept of LOCAL and GLOBAL variables.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As for long, MEANINGFUL NAMES for variables and functions \u2014 just look at the sample programs to see the improvement.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">David Gries suggests structured programming be called \u201csimplicity theory\u201d, and characterizes it as \u201can approach to understanding the complete programming process\u201d [Gries 1974]. As a pleasant dividend, structured programming is more enjoyable than monolithic programming. It should certainly, therefore, be a part of personal computing. To begin our look at tiny-c as a structured programming language, let\u2019s look at the foundation of functions and predictable program flow \u2014 the compound statement.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When you write a program, you write a list of statements:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>x = x-1 \na = b+c \nb = b*2-c \nx = b-a <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The idea behind a compound statement is to make one statement \u2013 a molecule \u2013 out of a set of statements \u2013 some atoms. This is done in tiny-c by<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;x = x-1 \n a - b+c \n b = b*2-c \n x = b-a] <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Anywhere you can write a simple statement you can also write a compound statement. This sounds simple, but the effect is powerful. For example most programming languages have an if statement similar to this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (logical expression) statement <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">So you can write<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (x&gt;0) x = x-1 <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">But make the statement part compound, and you have this capability:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (x&gt;0) &#91; \n    b = b*2-c \n    a = b+c \n    X = x-1 \n] <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This multiline <code>if<\/code> is not some special kind of <code>if<\/code>. It is still:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (logical expression) statement<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">But the statement part is compound. The compound statement is treated as an indivisible unit. It is either all done or all not done depending on the value of the logical expression.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The compound statement also is a natural for LOOPS. There is a big difference among the various programming languages in how you write loops, but they all have one thing in common. A loop has a beginning and an end. A compound statement can be used to express this. The looping statement is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>while (logical expression) statement<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Notice the similarity with the <code>if<\/code>. Only the keyword has changed. Here\u2019s how <code>while<\/code> works. The logical expression is evaluated. If it is true, then the statement is executed, and then the while is done again. The effect is a repeated if, i.e., a loop. As long as the logical expression remains true, the statement is done again and again. Eventually something in the statement causes the logical expression to become false, and the loop terminates. Of course, the statement can be compound, as in:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>while (x&gt;0) &#91; \n    a = b+c \n    b = b*2-c \n    x = x-1 \n] <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The compound statement is a natural way to delimit the beginning and end of loops.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With one simple idea, the compound statement, two things are achieved. The <code>if<\/code> statement is more powerful than is common in non-structured programming languages. The concept of a loop collapses to a simple repeated <code>if<\/code> or <code>while<\/code> statement. In both situations you are stating conditions under which the statement \u2014 whether simple or compound \u2013 is to be executed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Nesting Compound Statements<\/h3>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">ANYWHERE YOU CAN WRITE A SIMPLE STATEMENT, YOU CAN WRITE A COMPOUND STATEMENT.<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">That is a fundamental rule. A compound statement contains simple statements. Therefore a compound statement can contain compound statements. Figure 1-2 illustrates this.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">FIGURE 1-2<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91; x = x-1\n  a = b*c\n  b = b*2-a\n  x = b-a<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>a=b+c<\/code> is a simple statement. The rule says a compound statement can be written here. For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91; x = x-1 \n    &#91; a=b+c \n      w = y+2*x+w \n      y = 17 \n    ] \n  b = b*2-a \n  x = b-a \n] <\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">End of FIGURE 1-2<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The substitution of a compound for a simple shown in Figure 1-2 is certainly allowable, but is of no practical value.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The real utility in nested compounds is in writing nested if and while statements. Figure 1-3 is therefore a more realistic example of the use of compound statements.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">FIGURE 1-3<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>if (x&gt;0) &#91; \n    while (x&lt;limit) &#91;\n        if (case==1) &#91;\n            y = 0; w = 99\n        ]\n        if (case==2) &#91; \n            y = 99; w = 0\n        ] \n        nextaction \n        x = x+1 \n    ] \n\n] <\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">End of FIGURE 1-3<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In Figure 1-3, if you remove everything except the brackets, you have this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91; &#91; &#91; ] &#91; ] ] ] <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This is what is meant by compound statements. Brackets are used to form program units the same way parentheses are used to create arithmetic statements. The main difference is that a pair of brackets is preceded by a function name, or a logical expression. In the first case you\u2019re naming the contents of the brackets and in the second you\u2019re stating the conditions under which the contents are to be executed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Readable Program Flow<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In Figure 1-3, look at the \u201c<code>y=0<\/code>\u201d in the fourth line. How can it be reached? Only if case is 1, and <code>x<\/code> is less than limit. No go-to can lead here, either accidentally or on purpose.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How can \u201c<code>nextaction<\/code>\u201d be reached? Only if <code>x<\/code> is less than limit, and then only after possible changes to <code>y<\/code> and <code>w<\/code>. This program has simple, predictable flow. The only way a statement other than a while can be reached is from directly above, whiles can also be reached from their matching <code>]<\/code> below.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Indenting and the Placement of Brackets in Compound Statements<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The brackets alone define the \u201cstructure\u201d of a program. Indenting means nothing. But one of the purposes of structured programming is to make programs more readable and, hence, more understandable. A good choice of indenting style is very important to program readability. There are several styles to choose from. The actual choice is not too important. But once you choose a style, stick to it. Consistency IS important.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One easily explained style is to align matching brackets vertically. This looks like:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (x&lt;0) \n&#91;   statement \n    statement \n        \"\n        \"\n        \"\n] <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A problem with this is that when editing the first statement, care must be taken to keep the <code>[<\/code> intact. So some use this style:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (x&lt;0) \n&#91; \n\n    statement \n    statement \n        \"\n        \"\n        \"\n] <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This takes an extra line. Also there is a visual break between the if and its statements. So some take the left bracket and move it to the end of the preceding line:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (x&lt;0) &#91; \n    statement\n    statement \n        \"\n        \"\n        \"\n] <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The right bracket is now vertically aligned with the if or while that preceded the compound statement.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You may pick one of these, or invent a style of your own. But, we repeat, whatever you decide to do, do it consistently.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Functions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A large software project can usually be broken into natural parts, and each part programmed and debugged as a separate unit. Each of these units then becomes a reliable building block for the construction of still larger parts of the project. Sometimes units can be designed to be useful in many projects.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In various programming languages these building blocks are called subprograms, subroutines, or, as in tiny-c, FUNCTIONS. Here is a tiny-c function for any computer versus human game:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>game &#91; \n    getready \n    while ( stillplaying ()) &#91; \n       humanturn \n       if (stillplaying ()) computerturn \n    ] \n    gameover \n] <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The name of the function is \u201c<code>game<\/code>\u201d. The compound statement that follows is called the body of the function. Each <code>[<\/code> can be read as \u201cdo all of this\u201d, and its matching <code>]<\/code> read as \u201cend of this\u201d, game divides the design of a game program into five parts:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>getready (which initializes things, and \n          prints instructions if \n          requested), \n\nstillplaying (which determines if the \n              game is still going, and \n              returns true if it is, \n              otherwise false), \n\nhumanturn (which conducts the human's \n           turn), \n\ncomputerturn (which conducts the \n              computer's turn) , \n\ngameover (which computes and prints \n          scores, makes remarks about \n          the human's skill, promotes \n          the human, or whatever). <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The game function is the first step in divide-and-conquer or top-down program development. Let\u2019s carry this development one step further. The <code>getready<\/code> function can be expanded this way :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>getready &#91; \n    ps \"Do you want instructions?\" \n    if (gc()=='y') instructions \n    setupboard \n] <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>getready<\/code> divides the initialization into two parts: <code>instructions<\/code>, and <code>setupboard<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(Note: <code>ps<\/code> prints a character string, <code>gc()<\/code> reads a character, and <code>== 'y'<\/code> tests if the character is a y.)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Notice that both <code>game<\/code> and <code>getready<\/code> are universal. They can be used in many game programs. Programming in this fashion eventually leads to a library of useful, general purpose functions. These can be pulled off the shelf into a software project. You know they work because they were used before. Your programming becomes more productive, and more pleasant.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The next time you\u2019re programming a sizable project, i.e., anything more than a page, try to identify subsets of the logic usable in other projects. Capture these as functions. It is gratifying to discover a general purpose function where none was suspected.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Local and Global Variables<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A LOCAL VARIABLE is one that is known only inside a function. It can be used and changed only within the body of the function. Even its name is unknown outside the function. In fact, its name can be used in other functions without conflict. This is what makes local variables useful.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Take a look at Figure 1-4. There are four local variables in these two functions. The variables <code>n<\/code> and <code>maximum<\/code> are local to a function. The variables <code>n<\/code> and <code>total<\/code> are local to another function. If either of these functions calls the other, the values of <code>n<\/code> will not be confused since they only have meaning inside the body of their own functions. It helps to think of local variable names as being preceded by the possessive form of the function to which they are local. For example, a function\u2019s <code>n<\/code> and another function\u2019s <code>n<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">FIGURE 1-4<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>afunction &#91; \n    int n, maximum \n    n=0 \n    while (n&lt;maximum) &#91; \n          .\n          .\n          .\n        n=n+l \n    ] \n] \n\nanotherfunction &#91;\n    int n, total \n          .\n          .\n          .\n    n = n+2 \n    total = total+n \n          .\n          .\n          .\n] <\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">End of FIGURE 1-4<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The value of locals is obvious to anyone who has spent a nasty debugging session trying to find out where, in a huge program, some variable is getting changed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Of course not all variables can be local. Some must be shared by many functions. These are called GLOBALS. They should be used infrequently, as they do cause debugging headaches. Choosing good, descriptive names for globals alleviates the problem, . A global named \u201c<code>k<\/code>\u201d is inviting disaster. Call it \u201c<code>klingonsleft<\/code>\u201d and you\u2019re less likely to accidentally use it for two purposes. Also you\u2019ve given a reader of your program a pretty good clue to the variable\u2019s use.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Summary \u2013 And Where We Go From Here<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">We\u2019ve walked through a simple program to get a feel for tiny-c, and we\u2019ve discussed the virtues of structured programming. These are just the preliminaries. Now it\u2019s time for the main events. First, a complete definition of the tiny-c language. Chapter II is devoted to this task. To prepare programs you need an editor and way of debugging. The Program Preparation System (PPS) is described in Chapter III. Examples are excellent learning tools: Chapter IV has several example programs. Maybe you want to make it bigger, better, or faster? Chapter V explains how tiny-c works. Finally, of course you\u2019ll want to get tiny-c up and running on your own computer. Chapters VI and VII explain how to install tiny-c on an 8080 or PDP-11.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The project found this little manual instructive. You could say it is a kind of C flavour that is inspired by BASIC!<\/p>\n","protected":false},"author":1,"featured_media":205,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[9],"tags":[30,17],"class_list":["post-204","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-archeology","tag-c","tag-retrocomputing"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/permacomputer.solarpunk.au\/wp-content\/uploads\/2026\/06\/cover-page.jpeg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/permacomputer.solarpunk.au\/index.php?rest_route=\/wp\/v2\/posts\/204","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/permacomputer.solarpunk.au\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/permacomputer.solarpunk.au\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/permacomputer.solarpunk.au\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/permacomputer.solarpunk.au\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=204"}],"version-history":[{"count":6,"href":"https:\/\/permacomputer.solarpunk.au\/index.php?rest_route=\/wp\/v2\/posts\/204\/revisions"}],"predecessor-version":[{"id":211,"href":"https:\/\/permacomputer.solarpunk.au\/index.php?rest_route=\/wp\/v2\/posts\/204\/revisions\/211"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/permacomputer.solarpunk.au\/index.php?rest_route=\/wp\/v2\/media\/205"}],"wp:attachment":[{"href":"https:\/\/permacomputer.solarpunk.au\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/permacomputer.solarpunk.au\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=204"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/permacomputer.solarpunk.au\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}