Preconditions and Postconditions
-
One good way to write a function prototype comment is to break it down into two kinds of information called a precondition and a postcondition.
-
The precondition states what is assumed to be true when the function is called. The function should not be used if the preconditions do not hold.
-
The postcondition describes what will be true after the function is executed in a situation in which the precondition holds.
-
For a function that returns a value, the postcondition describes the value returned by the function.
-
For a function that changes the value of some argument variables, the postcondition describes all the changes made to the values of these arguments.
-
From the function prototype and the preconditions and postconditions,
one can correctly use the function without knowing the definition of the function.