Sams Teach Yourself C in 21 Days

(singke) #1
Advanced Compiler Use 597

21


Module Components ....................................................................................

As you can see, the mechanics of compiling and linking a multiple-module program are
quite simple. The only real question is what to put in each file. This section gives you
some general guidelines.
The secondary module should contain general utility functions—that is, functions that
you might want to use in other programs. A common practice is to create one secondary
module for each type of function—for example, keyboard.c for your keyboard functions,
screen.c for your screen display functions, and so on. To compile and link more than two
modules, list all source files on the command line:
tcc mainmod.c screen.c keyboard.c
The main module should contain main(), of course, and any other functions that are pro-
gram-specific (meaning that they have no general utility).
There is usually one header file for each secondary module. Each file has the same name
as the associated module, with an .h extension. In the header file, put


  • Prototypes for functions in the secondary module

  • #definedirectives for any symbolic constants and macros used in the module

  • Definitions of any structures or external variables used in the module


FIGURE21.3
A Project opened in
Dev-C++.

33 448201x-CH21 8/13/02 11:16 AM Page 597

Free download pdf