CST 8152 Compilers - Assignments #1&2Evaluation Sheet II - Common Errors
1. should use #define for these constants
- modifying this program is difficult
- write it once; change it once
2. this is not a pointer variable; dont use NULL
- int i = NULL; /* misleading */
- char *p = 0; /* misleading */
3. read input in only one place (makes EOF testing easier!)
4. no check for buffer overflow
- if your program cannot handle arbitrary length input, it must protect itself against buffer overflow and tell the user when the limit is crossed
5. fgetc() returns an integer, not a character
6. no check for return code of function
7. redundant or superfluous code (unknown purpose or utility)
8. type mismatch (e.g. char */int, void/int, etc.)
- char *func()
return 10; /* wrong */
- int func()
return abc; /* wrong */
9. function returns pointer to local stack storage
- func(){ char x[SIZE]; return x; } /* wrong */
10. output doesnt conform to assignment requirements
11. scanf() is not appropriate for line input from human beings
- use fgets() followed by sscanf()
12. missing pseudocode, or pseudocode does not match code