Commenting And Documentation
General Tips
- Always use
\\
style comments where possible. This allows you to use/*
style comments for commenting out large blocks of code when debugging. If you want to comment a block of code which has/*
comments inside it, you will run into problems! (unfortunately,*/
style comments don’t nest in c). - However, sometimes you still need to comment out blocks of code which have
/*
comments already inside them (maybe your using someone elses code?). To do this, you can use the preprocessor trick#if 0
(see code below).
C Supports URL’s, Wait What?
Did you know that:
is valid syntax in C? Wait, what? O.K., I was lying, C doesn’t support URLs, but the syntax is still valid! What it actually represents is a label (http:
), followed by a single-line comment (//www.google.com
).
Commenting Styles
Some people put function descriptions after the function name and parameters, and before the opening curly brace (for example, some windows driver files). I find this method weird and hard to read.
Doxygen
Doxygen is a powerful documentation generator that can be used with the C language. For more information and code examples with Doxygen, go to the Doxygen page.