Scholarly Resources for CompSci Undergrads

C Programming Language

Notes about C Debugging

Notes to Accompany Annotated Example in Lecture Notes: HTML/JavaScript version

  1. From an old assignment (a child's arithmetic quiz) [back]
  2. Good documentation habits include always explaining the purpose of variables, and using sensible names that are not too similar. I like to see pre- and post-conditions in code that I grade. These exact form of these documentation habits are a matter of style but you should always provide the same information. (Kernighan & Pike's The Practice of Programming (Addison-Wesley, 1999) has another good style.) [back]
  3. It is sometimes useful to show the parameters passed to a function. When you do, also show the names so you can't accidentally pass them in the wrong order. D'oh! [back]
  4. Note the continuation here [back]
  5. I prefer to use {}s for all if statements. That way I can easily insert more code without forgetting the {. (This is especially easy mistake to make if you use macros.) [back]
  6. There's no { here. That's a problem waiting to happen. [back]
  7. Notice that I always use a default case with a switch. It takes very little time to code but can save a great deal of time later. [back]
  8. Along with a good indentation style (which I will not discuss here) I find labelling closing braces that are far away from their corresponding opening braces. If you type the start and end of functions at the same time (like you type closing parentheses when you type the opening ones) then this is easy to do. [back]

http://www.csd.uwo.ca/~jamie/C/Debug/LectureNotes/comm-all.html

Last updated by J. Blustein on 28 April 2002.

This document is copyright by its author, J. Blustein <jamie@csd.uwo.ca>.