Chapter 18. Modular Programming

Many hands make light work.

John Heywood

All along, we have been dealing with small programs. As programs grow larger and larger, it is more desirable to split them into sections or modules. C allows programs to be split into multiple files, compiled separately, and then combined (linked) to form a single program.

In this chapter, we will go through a programming example, discussing the C techniques needed to create good modules. You will be shown how to use make to put these modules together to form a program.

Modules

A module is a collection of functions that perform related tasks. For example, a module could exist to handle database functions such as lookup, enter, and sort. Another module could handle complex numbers, and so on.

Also, as programming problems get bigger, more and more programmers are needed to finish them. An efficient way of splitting up a large project is to assign each programmer a different module. In this manner, each programmer only worries about the internal details of a particular module.

In this chapter, we will discuss a module to handle infinite arrays. The functions in this package allow the user to store data into an array without worrying about its size. The infinite array grows as needed (limited only by the amount of memory in the computer). The array will be used to store data for a histogram, but can be used to store things like line numbers from a cross-reference program or other types of data.

Public and Private

Get Practical C Programming, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.