This is not a formal standards document. Rather, it contains style guidelines for C programs to make them easier (for me) to read and debug them.

Programs written for this course must satisfy the following guidelines. For examples of such programs, see the programs in USP.

  1. include files
    1. include file should only contain macro and type definitions, typedefs, and function prototypes.
    2. All system include files should come first, starting with those at the top level in alphabetical order, followed by those in subdirectories.
    3. These are followed by user include files in alphabetical order.
    4. These are followed by defined constants
    5. These are followed by prototypes
    6. On some systems that do not follow the POSIX standard, the ordering of the include files may have to be modified.
  2. main:
         int main(void) {
         int main(int argc, char *argv[]) {
  3. Do not start a new line for the opening brace for functions.
  4. Indent 3 spaces for each level
  5. Comments right justified
  6. No lines longer than 80 characters
  7. Blocks: starting brace does not start a new line.
    Indent three spaces. Do not use tab characters in your file.
    Ending brace lined up with statement containing the matching brace.
  8. No program should ever have a possibility of a buffer overflow.
  9. Main programs that take parameters should check for the correct number of parameters and print a usage message if incorrect.
  10. Local variables in alphabetical order
  11. Use functions (internal and external) liberally to modularize your programs.
  12. Use separate compilation.
  13. Use the static modifier to hide private functions and global variables whenever possible.
  14. Use variables with external linkage only when necessary.
  15. Use make.