Page Name: CoreCourses / StyleGuide

C Coding Style Guide

This document sets out the mandatory style for all submitted C code in first year CSE courses.

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 (not used in first year CSE courses)
  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 (not used in first year CSE courses)

A header comment should include:

// WikiName (or full name for offerings without a wiki), Student Login.
// Tutorial class and tutor name
// Date
// What this file is for (one line summary).

// Possible longer explanation

Names

Layout

if, while

Declarations

Functions

Executable Statements

Function definitions

Structs

typedefs

Comments

Compiler Options

Structured Programming

No shortcuts

C syntax discouraged

Security

Thanks

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.

last edited 2011-04-28 06:18:20 by RichardBuckland