C Coding Style Guide

This is the style guide for COMP2521.

  1. C Program Layout
  2. Names
  3. Layout
  4. if, while
  5. Declarations
  6. Functions
  7. Executable Statements
  8. Function definitions
  9. Structs
  10. typedefs
  12. Compiler Options
  13. Structured Programming
  14. No shortcuts
  15. C syntax discouraged
  16. Security
  17. Thanks

C Program Layout

In a C program file items must be arranged in the following sequence:

  1. Header comment
  2. #included files
  3. #defines
  4. local struct typedefs
  5. local prototypes
  6. global vars (to be used very sparingly)
  7. main function (if present)
  8. local functions

In a C header (.h) file items must be arranged in the following sequence:

  1. Header comment
  2. #ifndef guard
  3. #included files
  4. #defines
  5. struct typedefs
  6. prototypes
  7. (extern) global vars (to be used very sparingly)

A header comment should include:

// Student name and unsw email address
// Tutorial class and tutor name
// Date
// What this file is for (one line summary).

// Possible longer explanation



if, while



Executable Statements

Function definitions




Compiler Options

Structured Programming

Your code must NOT use the goto statment.

You may use



Parts of the initial version of this document was based on "Appendix C: C Programming Standards" of Programming Techniques using the language C, Government of South Australia, Pearson Education Australia 2005. Subsequently it has been expanded and revised based on the experiences of using it in our courses. It has benefited from the suggestions and comments of numerous 1911, 1921, 1917, 1927 and 2911 teaching staff and tutors. Thank you to all who have contributed.