Example Program
The following program, BADCODE.C, is one of the example programs provided with the Keilevaluation kits. This program has a lot of errors and is intended to demonstrate the error detecting and correcting capabilities of theµVision IDE.
Following are listings of the example program (with mistakes highlighted in red), output from the C51 compiler, and output from PC-Lint. The C51 Compiler detects and reports12 errors and warnings while PC-Lint detects and reports 26 errors and warnings.
/*------------------------------------------------------- BADCODE.C Copyright Keil - An ARM Company This source file is full of errors. You may use µVision to compile and correct errors in this file. -------------------------------------------------------*/ #incldue <stdio.h> void main (void, void) { unsigned i; long fellow; fellow = 0; fer (i = 0; i < 1OOO; i++) { printf ("I is %u\n", i); fellow += i; printf ("Fellow = %ld\n, fellow); printf ("End of loop\n") } }
C51 Output
When compiled with the C51 compiler, the BADCODE program generates the following errors and warnings:
C51 COMPILER Copyright (c) KEIL - An ARM Company. All rights reserved. *** ERROR 315 IN LINE 10 OF BADCODE.C: unknown #directive 'incldue' *** ERROR 159 IN LINE 12 OF BADCODE.C: 'typelist': type follows void *** WARNING 206 IN LINE 19 OF BADCODE.C: 'fer': missing function-prototype *** ERROR 267 IN LINE 19 OF BADCODE.C: 'fer': requires ANSI-style prototype *** ERROR 141 IN LINE 19 OF BADCODE.C: syntax error near ';' *** ERROR 141 IN LINE 19 OF BADCODE.C: syntax error near 'OOO' *** ERROR 202 IN LINE 19 OF BADCODE.C: 'OOO': undefined identifier *** ERROR 141 IN LINE 19 OF BADCODE.C: syntax error near ')' *** WARNING 206 IN LINE 21 OF BADCODE.C: 'printf': missing function-prototype *** ERROR 103 IN LINE 24 OF BADCODE.C: '<string>': unclosed string *** ERROR 305 IN LINE 24 OF BADCODE.C: unterminated string/char const *** ERROR 141 IN LINE 25 OF BADCODE.C: syntax error near 'printf' C51 COMPILATION COMPLETE. 2 WARNING(S), 10 ERROR(S)
PC-Lint Output
When checked with PC-Lint, the BADCODE program generates the following errors and warnings:
--- Module: badcode.c badcode.c 10 Error 16: Unrecognized name badcode.c 10 Error 10: Expecting end of line badcode.c 12 Error 66: Bad type badcode.c 12 Error 66: Bad type badcode.c 19 Info 718: fer undeclared, assumed to return int badcode.c 19 Info 746: call to fer not made in the presence of a prototype badcode.c 19 Error 10: Expecting ',' badcode.c 19 Error 26: Expected an expression, found ';' badcode.c 19 Warning 522: Expected void type, assignment, increment or decrement badcode.c 19 Error 10: Expecting ';' badcode.c 19 Error 10: Expecting ';' badcode.c 21 Info 718: printf undeclared, assumed to return int badcode.c 21 Info 746: call to printf not made in the presence of a prototype badcode.c 23 Info 737: Loss of sign in promotion from long to unsigned long badcode.c 23 Info 713: Loss of precision (assignment) (unsigned long to long) badcode.c 24 Error 2: Unclosed Quote badcode.c 25 Error 10: Expecting ',' badcode.c 26 Error 10: Expecting ',' badcode.c 26 Error 26: Expected an expression, found '}' badcode.c 26 Warning 559: Size of argument no. 2 inconsistent with format badcode.c 26 Warning 516: printf has arg. type conflict (arg. no. 2 -- pointer vs. unsigned int) with line 21 badcode.c 27 Warning 550: fellow (line 15) not accessed --- Global Wrap-up Warning 526: printf (line 21, file badcode.c) not defined Warning 628: no argument information provided for function printf (line 21, file badcode.c) Warning 526: fer (line 19, file badcode.c) not defined Warning 628: no argument information provided for function fer (line 19, file badcode.c)
As you can see, the quantity and quality of the error messages reported by PC-Lint is greater than that reported by the C compiler.