Chapter 21. Subprograms

Table of Contents

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

Motivation

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

Table 21.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.