Site hosted by Angelfire.com: Build your free website today!



Next: Compiling Multi-File Programs Up: Programs with Several Previous: How to Divide

Organisation of Data in each File

Any file must have its data organised in a certain order. This will typically be:

  1. A preamble consisting of #defined constants, #included header files and typedefs of important datatypes.
  2. Declaration of global and external variables. Global variables may also be initialised here.
  3. One or more functions.

Within each of these sections, the order of items is important, since any object must be defined before it can be used. In particular, functions which return values must be defined in the file before they are called. This definition might be one of the following:

A function defined as

  float find_max(a, b, c)
  float a, b, c;
  {  /* etc ... ... */
would have a dummy declaration of

  float find_max();
The dummy declaration may occur among the global variables, or be local to each function where it is called. Dummy declarations can also be made in header files, which are read in using #include.

It is most important to remember that all C objects should be declared before they are used.