Programming Style
The minimal style requirements for programs handed in as
part of assigments are as follows:
- All the programs must use Standard (``ANSI'') C. ``Traditional C''
is not to be used where it conflicts with Standard C.
- Your programs must compile and execute properly on the Erindale
CS Lab machine tuzo. It is not enough that your program works correctly
on your home machine.
- All functions, except main, must have prototypes, even if the
prototype immediately precedes the function definition.
- All function definitions (except main) must be preceded by an
explanatory comment stating completely but concisely the purpose
of the function, including the role of all function arguments.
Note that this comment must come immediately before the function
header, not after. Note also that the comment does not describe
the implementation of the function unless that is an unavoidable
part of specifying the interface.
-
Global variables are nearly forbidden. ``Nearly forbidden'' means
that you may only use a global variable if you write a comment
justifying its use next to the declaration that defines it. Your
tutor may reject the explanation, in which case you will be
considered to have broken the rule.
-
``Magic numbers'' are forbidden. Use #define to give names to constants.
The only exception is zero, which can be used as a success or failure
return value from functions, and the null character is '\0'.
For example, use constants ``true'' and ``false'' #defined to 1 and
0 respectively. These are not the conventional C definitions,
but they agree with C++, so we should get used to them.
-
Your programs must be indented or paragraphed to help the marker
read them. On Unix, use cb or indent, or do it by hand.