Breakout, the game the course builds in HiSoft C, running on the Tatung Einstein: coloured brick rows, the bat and the ball on a black court
← Back to Courses
module
7

When It Goes Wrong

Introduction

You are going to get things wrong, constantly; everyone does. What matters is how fast you can read the message and get back to the editor - and HiSoft C has a trick for that which was a selling point in 1985. This section makes each kind of mistake on purpose, so that you have seen them before they find you: the ones the compiler catches at once, the one it catches at the end, and the two it does not catch at all.

The Compiler

Take S4's program and leave the semicolon off the printf line:

#include STDIO.H

main()
{
    printf("Hello, Einstein\n")
}

#include ?STDIO.LIB?

Save it as ERR1.C and compile it:

0:HC ERR1.C
HiSoft-C Compiler V1.35 Copyright (C) 1985
Line File
     ERR1.C
ERROR 0 AT LINE 6 IN FILE ERR1.C
missing ';'

and then nothing. The prompt does not come back. Read the message first: ERROR, a number, the line and the file, and on the next line what is wrong - missing ';'. The line it names is 6, the }, not 5 where the semicolon should have been. The compiler read printf(...), expected a ;, and did not find out it was missing until it met the } on the next line. So the message says what; the line says where the compiler noticed; and the mistake is usually on that line or the one before. The number is for looking up in the manual's chapter of errors, which explains every one.

The compiler stops at the first error it finds. Fix that one and compile again; there may be more, but it will only ever tell you one at a time.

The Key That Waits

The compiler is waiting for you to press a key, and which key matters.

Press E. About six seconds later ED80 opens, on the faulty file, with the cursor on the line the message named:

ERR1.C          LINE:6    COL:1
#include STDIO.H

main()
{
    printf("Hello, Einstein\n")
}

#include ?STDIO.LIB?

Now fix it: GRPH-E to go up to the printf line, GRPH-Q D to its end, type the ;, and GRPH-K X and ENTER to save. And here is the trick: you are not returned to the prompt. The compiler starts again by itself, compiles the corrected file, and this time prints the map. That is the whole cycle - compile, read, E, fix, save - and it is the reason the editor is on the disc under the name ED80.COM as well as ED: the compiler runs it by that name.

Any other key at the wait returns you to 0:, which is what you want when the fix is in a different file, or when you would rather think first.

The Error At The End

Now a different kind of mistake. Put the semicolon back and misspell printf:

    prinf("Hello, Einstein\n");
0:HC ERR2.C
HiSoft-C Compiler V1.35 Copyright (C) 1985
Line File
ERROR - 27 - undefined symbol prinf

No line number, and the compiler had read the whole file before it said anything. In C a name followed by brackets is a function, and a function can be defined further down the file - or in the library, which comes last - so the compiler cannot know a name is undefined until it has seen everything. Then it tells you, once, by name. This is the message you get for any name nothing defines: a misspelt function, a function you meant to write and did not, a main typed as MAIN with CAPS LOCK on.

Words It Does Not Know

A few messages you will meet in this course, each made on purpose in a later section:

MessageWhat you did
ERROR 46 ... RESTRICTION: Floating Point not implementedUsed float or double. There are none (S9).
ERROR 3 ... not a preprocessor commandUsed #if, #ifdef, #ifndef or #undef. There is no conditional compilation here (S19).
ERROR 6 ... RESTRICTION: macros may not have parameters#define with brackets (S19).
ERROR 61 ... RESTRICTION: use assignment or blt() to initialise automaticsint i = 1; inside a function (S10).
ERROR 32 ... bad type combinationPut a number into a pointer, or a structure into a structure (S16, S18).
ERROR 36 ... expecting a primary hereA declaration in the middle of a function, or a cast written (char *) (S10, S16).
ERROR 56 ... bad formal parameter listWrote the types inside a function's brackets (S13).

RESTRICTION means a piece of C the compiler knows about and does not do; LIMIT means your program has outgrown one of its tables. The manual lists all sixty-five messages with a paragraph each.

The Silent Ones

Two mistakes this compiler lets through without a word, and the second is worse than silence.

Arithmetic that overflows or divides by zero carries on and gives the wrong answer. S9.

A function called with the wrong number of arguments. It compiles. When it runs, the machine stops making sense - and not always in the same way. One time it was two characters of rubbish and the prompt; one time nothing at all, for as long as anyone waited; and one time this:

 A  BC   DE   HL   PC  SZ-H-PNC
20 00FF 6C01 0000 7001 01101010
>

That is the Einstein's built-in monitor, which it falls into when the program it was running stops being a program. Nothing is lost on the disc. Restart the Einstein, and count the arguments at every call. S13 shows why.

And one that is not the compiler's fault at all: a loop that never ends. Nothing you press will stop it - not CONTROL-C, not BREAK. The only way out is to restart the Einstein, which is why you save before you run. S12 shows how a loop watches the keyboard and stops itself.

The Code

The two broken programs above, typed and saved as ERR1.C (no ;) and ERR2.C (prinf).

Starting from

A fresh boot; each typed in ED80 and saved.

What you should see

HC ERR1.C: ERROR 0 AT LINE 6 IN FILE ERR1.C, missing ';', and a wait; E, ED80 at line 6; the fix, GRPH-K X, ENTER; the compiler's sign-on again and the map. HC ERR2.C: ERROR - 27 - undefined symbol prinf.

Change One Thing

  • In ERR1.C, put the semicolon back and take away the closing } instead. What does the compiler say, and what line does it say it on?
  • Press a key other than E at the wait. Where are you?
  • In ERR2.C, misspell main as Main instead. Which message do you get, and why that one?

Exercises

7.1 Without compiling, say which of these the compiler will report at once, which at the end, and which will run: (a) printf("x") with no ;; (b) printf("x" with the bracket missing; (c) printf("x"); spelt prinf; (d) a program with two mains.

7.2 Make a program with two mistakes on different lines, and see how many the compiler reports. Fix the first with E, and count again.

Worked solutions are in Appendix II.

When It Goes Wrong

SymptomCause
The line shown is not the one with the mistakeThe compiler noticed one line late. Look at the line before.
The prompt does not come back after an errorThe compiler is waiting. E for the editor; anything else for the prompt.
undefined symbol with no line numberA name nothing defines - a misspelling, or CAPS LOCK.
RESTRICTIONA piece of C this compiler does not do. The section named above says what to do instead.
An error IN FILE STDIO.LIB when you did not touch the libraryA } is missing in your file, so the compiler was still inside your function when it reached the last line and read the library there. Count your braces.
A register dump and >, or rubbish characters, or a program that prints nothing and never returnsThe program crashed, most likely a call with the wrong number of arguments. Restart the Einstein.
The program never comes back and no key stops itA loop that does not watch the keyboard. Restart the Einstein.

Summary

ERROR nn AT LINE n names the line where the compiler noticed; it stops at the first error; E takes you to the editor on that line and the compile restarts when you leave. An undefined name is reported at the end, without a line. Wrong argument counts crash into the monitor, and nothing stops a runaway loop.

Next

S8, Printing - what printf can print, how to lay it out, and where the library it lives in comes from.

Get the Newsletter

New guides, disk images and community finds, roughly once a quarter. No spam, we promise, this isn't Tatung's marketing department.
Your subscription could not be saved. Please try again.
Your subscription has been successful.

Newsletter

Subscribe to our newsletter and stay updated.