Chapter 20. Subprograms

Table of Contents

20.. Motivation
20.. Modular Design
Abstraction and Layers
20.. Subprogram Implementation
20.. Fortran Subprograms
20.. Internal vs External Subprograms
20.. Defining Your Own Fortran Functions
20.. Defining Your Own Subroutines
20.. C Subprograms
20.. Scope
20.. Scope
Self-test
20.. Storage Class
Auto
Static
Register
Dynamic
Self-test
20.. Argument Variables
Type Matching
Argument Passing Details
Intent
20.. Top-down Programming and Stubs
20.. C Preprocessor Macros
20.. Recursion
20.. Creating your own Libraries
20.. Self-test

Motivation

Most real-world programs are too large for the human mind to deal with all at once.

Table 20.1. Program Sizes

ProgramSize
ispell10,000 lines
ape13,000 + 13,000 twintk
pico25,000
GNU Fortran Compiler278,000

The only way to grasp programs of this scale is by designing and implementing them as a collection of smaller programs.