Error Checking and Reporting

From HI-TECH C for CP/M Fan WIKI(EN)
Jump to: navigation, search

Errors may be reported by any pass of the compiler, however in practice the assembler and optimizer will not encounter any errors in the generated code. The types of errors produced by each pass are summarized below. In gen- eral any error will be indentified by the name of the source file in which it was encountered, and the line number at which it was detected. P1 will also nominate the name of the function inside which the error was detected.

Errors may be redirected to a file with the usual syntax, i.e. a 'greater than' symbol ('>') followed by the name of a file into which the errors should be written. The file name may of course be a device name, e.g. LST: for CP/M or PRN for MS-DOS.

CPP will report errors relating to macro definitions and expansions, as well as conditional compilation.

P1 is the pass which reports most errors; it performs syntax and semantic checking of the input, and will report both fatal and warning errors when encountered. Syntax errors will normally be expressed as "symbol expected" or "symbol unexpected". Semantic errors may relate to undeclared, redeclared or misdeclared variables. P1 will also report variable definitons which are unused or unreferenced. These errors are warnings, as are most type checking errors.

When P1 encounters errors it will list the source line containing the error on the screen, and underneath display the error message and an up arrow pointing to the point at which the compiler detected the error. In some cases the actual cause of the error may be earlier in the line or even on previous line.

CGEN may occasionally report errors, usually warnings, and mostly related to unusual combinations of types with constants, for example testing if an unsigned quantity is less than zero. One fatal error produced by CGEN is "can't generate code for this expression" and means that the expression currently being compiled is in some way too complicated to produce code for. This can usually be overcome by rewriting the source code. Such errors are rare and will occur only for unusual constructs.

The linker will report undefined or multiply defined symbols. Note that variable declarations inside a header file which is included in more than one source file must be declared as extern, to avoid multiply defined symbol errors. These symbols must then be defined in one and one only source file.

A comprehensive list of error messages is included in an appendix.