Portability in C—A Case Study


Citation

Paper

Bibliographic Information

Abstract

There are a large number of computers and operating systems in use today, and more and more programs are being moved from one computer or operating system to another. In fact, when you complete a program, your job is often only half done; since you almost certainly have access to other computers, you will want to make the program portable enough to run on all of those machines. Taking some care while writing the program can greatly reduce, or even eliminate, the difficulty of such ports.

In this article we will examine several C programming constructs that produce more portable programs. We will do this in three stages, looking first at dependencies upon the compiler, then at dependencies upon the operating system, and finally at dependencies upon the computer architecture. Each of these considerations affects different parts of the program.

The vehicle we shall use is a program called trnum. This program is used to number equations, tables, and any other text you like; the numbers are given to trnum as symbols and are converted to numbers by that program. It was written before UNIX System V was available, and was ported to that operating system with literally no changes. So, the goal of programs which can be ported without changing anything is not an impossible dream.

Copyright Notice

©1986 by Matt Bishop. The definitive version was published in The C Journal 1(4), Winter 1986.