There are a few other things that you should keep in mind as you write
functions in C.
The most obvious thing to remember is to use comments. Every function
should be preceded by a comment that describes what the function does, what
arguments the function takes, and what value the function returns. It may or
may not be necessary to describe how the function does its job,
depending on how complicated the function is.
Take a look at the ``rods.c'' program. Notice that the distance
function uses the square function that was defined earlier in the file.
What do you think would happen if you moved the definition of the square
function to come after the definition of the distance function?
Click here for the answer.
The C compiler would warn you that distance was calling a function that
had not yet been defined. Always put the definition of a function before
the statements that invoke the function.
Eric N. Eide
Hamlet Project
Department of Computer Science
University of Utah