15 Working with Larger Programs
15 Working with Larger Programs
THE PROGRAMS THAT HAVE BEEN ILLUSTRATEDthroughout this book have all been
very small and relatively simple. Unfortunately, the programs that you will have to devel-
op to solve your particular problems will probably be neither as small nor as simple.
Learning the proper techniques for dealing with such programs is the topic of this chap-
ter. As you will see, C provides all the features necessary for the efficient development of
large programs. In addition, you can use several utility programs—which are briefly
mentioned in this chapter—that make working with large projects easier.
Dividing Your Program into Multiple Files
In every program that you’ve seen so far, it was assumed that the entire program was
entered into a single file—presumably via some text editor, such as emacs,vim, or some
Windows-based editor—and then compiled and executed. In this single file, all the func-
tions that the program used were included—except, of course, for the system functions,
such as printfand scanf. Standard header files such as <stdio.h>and <stdbool.h>
were also included for definitions and function declarations.This approach works fine
when dealing with small programs—that is, programs that contain up to 100 statements
or so. However, when you start dealing with larger programs, this approach no longer
suffices. As the number of statements in the program increases, so does the time it takes
to edit the program and to subsequently recompile it. Not only that, large programming
applications frequently require the efforts of more than one programmer. Having every-
one work on the same source file, or even on their own copy of the same source file, is
unmanageable.
C supports the notion of modular programming in that it does not require that all the
statements for a particular program be contained in a single file.This means that you can
enter your code for a particular module into one file, for another module into a different
file, and so on. Here, the term modulerefers either to a single function or to a number of
related functions that you choose to group logically.