Common Mistakes List
If a mistake is committed often enough, it will eventually be enshrined here, for all to see.
The upside of this is that people can learn from the mistakes of others. The downside of this is
that any mistake that appears on this page will carry a double penalty in the future. In other
words, think of these as forbidden mistakes from here on out.
- Compile your code with gcc -Wall -std=c99, and fix any warnings it gives you. If you
want to enforce this, use gcc -Wall -Werror -std=c99. Again, fix the warnings, as I
will start compiling with -Werror in the near future.
- Put your name in your files.
- Don't use %d for every argument to printf. Unsigned values need to be printed
with %u, longs with %ld, etc. Otherwise, you'll get odd/incorrect
output.
- Comment your code. Even if you think it's obvious, comment it anyway. If you have an upper
limit on a loop, tell me why. If you have a constant you're comparing a variable to, why?
- main is a function. It has a return type of int and arguments of int
argc and char **argv. Alternatively, you can use char *argv[], if you
prefer. This issue is not open for discussion, so just do it.
- Put your name in your files.
- Styles required in other classes have 0 impact on the style required in this class. Likewise,
style requirements in this class have no impact on styles required in other classes. In other
words, style guides are typically class specific. Get used to this, as it's something that will
not go away as long as you are working with code.
- Every single file you write should contain a block comment at the top of the file, containing
your name, when the file was created, and when it was last modified. It should also contain a
description of the purpose/contents of the file.
/*
* Original Author: D. Kevin McGrath (dmcgrath)
* File: example.c
* Created: 2009 September 22, 13:48 by dmcgrath
* Last Modified: 2009 September 22, 13:48 by dmcgrath
*
* This file contains functions related to blah blah blah.
*/
- Put your name in your files.
- Don't use magic numbers. If you need an arbitrary value, create a constant to hold it, give it
a descriptive name, and put in a comment to explain what it means.
- If you find yourself writing speacial case logic, you are likely doing something wrong.
- Test your code. If it runs longer than a minute, there is something wrong. And going from 0 to
the maximum value stored in a double or long by adding 1 is a BAD IDEA. In other words, stop and
think about what you're doing before you start typing.
- Please read the style guide. And follow it. Or you will lose points and get a poor grade.
- Strings in C end in the null character '\0'.
D. Kevin McGrath
Last modified: Thu Feb 21 13:32:35 2013