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.

The order of items is important, since every object must be defined before it can be used. Functions which return values must be defined before they are called. This definition might be one of the following:

A function defined as

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

  float find_max(float a, float b, float c);
The prototype may occur among the global variables at the start of the source file. Alternatively it may be declared in a header file which is read in using a #include.

It is important to remember that all C objects should be declared before use.


January 1995