by Safety1stClyde · 9y ago · 0 comments
I don't think this is a particularly useful thing to do. Essentially it is somewhat like making a compiler which accepts broken inputs using heuristics to guess at what the programmer intended to write. That will not result in better programs being written, rather it will result in the programmer not only writing worse code but not even being aware of the flaws in their code.
It repeatedly says that the aim is to fix errors. Assuming, however, that it is intended to give better error messages, here is the output of Clang on the input C program given as an example:
$ cc gupta.c
gupta.c:3:5: warning: incompatible redeclaration of library function 'pow'
[-Wincompatible-library-redeclaration]
int pow(int a, int b);
^
gupta.c:3:5: note: 'pow' is a builtin with type 'double (double, double)'
gupta.c:14:23: error: function definition is not allowed here
int pow(int a, int b){
^
gupta.c:18:14: error: expected ';' at end of declaration
return res;}
^
;
gupta.c:18:14: error: expected '}'
gupta.c:4:11: note: to match this '{'
int main(){
^
1 warning and 3 errors generated.
It identifies the problematic line of the program code better than gcc. The function declaration within main is not legal. I tried this with the gcc compiler and did not get the error above. Running "indent" on the code would have revealed the problems:$ indent < gupta.c
/INDENT Error@18: Stuff missing from end of file */
A simple count of braces, { and }, would also have revealed the problem.