Self-Assessment Quiz: Modules
Twenty questions to confirm you can build, expose, split, and compile modules before you move on to derived types. Aim for 16 or more. Answers and a topic map are at the end — try the whole quiz first.
Question 1
A module is best described as:
- A. A program that runs on its own
- B. A container for shared constants, variables, types, and procedures that other units access with use
- C. A single procedure that can be called from anywhere
- D. A file of preprocessor macros
Question 2
What does use kinds, only: dp do that a bare use kinds does not?
- A. It makes the import faster at run time
- B. It imports only dp, documenting the dependency and avoiding name clashes with other imports
- C. It makes dp private
- D. Nothing; the only: clause is decorative
Question 3
A module procedure is:
- A. Any subroutine in any file
- B. A subroutine or function defined after a module's contains statement
- C. A procedure declared with COMMON
- D. A procedure that must be pure
Question 4
A bare private statement (no list) at the top of a module:
- A. Makes the module uncompilable
- B. Hides every entity by default, so only those you explicitly mark public are visible outside
- C. Makes every entity public
- D. Applies only to variables, not procedures
Question 5
"An explicit interface for free" means that, because a procedure is in a module: - A. It runs faster - B. The compiler knows its full signature at every call site and checks calls against it - C. It never needs arguments - D. It is automatically parallel
Question 6
Which Chapter 6 feature does not require an explicit interface to work across files? - A. Keyword arguments - B. Optional arguments - C. Assumed-shape array arguments - D. A subroutine with only fixed-size scalar arguments passed positionally
Question 7
A private module variable can be changed from outside the module by:
- A. Assigning to it directly
- B. Only through the module's public procedures
- C. An INCLUDE statement
- D. Any program that uses the module
Question 8
Module variables are implicitly:
- A. allocatable
- B. save (they persist for the whole run and keep their value between calls)
- C. pointer
- D. re-initialized on every procedure entry
Question 9
A submodule exists to:
- A. Be used directly by programs
- B. Hold the bodies of separate module procedures whose interfaces are declared in the parent module
- C. Replace the main program
- D. Store data only
Question 10
Which prefix marks an interface body in a module as a separate module procedure (body in a submodule)?
- A. external
- B. pure
- C. module (e.g., module function ...)
- D. recursive
Question 11
The main practical benefit of submodules is: - A. Faster generated code at run time - B. Faster builds — editing a submodule body does not force recompilation of the parent module's users - C. Smaller executables - D. Automatic parallelism
Question 12
Inside a submodule, entities of the parent module (like a kind dp) are available:
- A. Only after a use of the parent
- B. By host association, with no use needed
- C. Never
- D. Only if declared public
Question 13
The modern replacement for a FORTRAN 77 COMMON block is:
- A. An EQUIVALENCE statement
- B. A module (with the shared state kept private and reached through procedures)
- C. A GOTO
- D. A pointer
Question 14
Why is a COMMON block dangerous compared to a module?
- A. It is slower
- B. Different routines can declare the same shared memory with different names, types, or lengths, and nothing checks the mismatch
- C. It cannot hold real numbers
- D. It requires a submodule
Question 15
A .mod file contains:
- A. The compiled machine code of the module's procedures
- B. The module's public interface (names, types, signatures) that a user needs at compile time
- C. The program's output
- D. The linker script
Question 16
The machine code for a module's procedures lives in:
- A. The .mod file
- B. The object (.o) file, which must still be linked
- C. The source file only
- D. Nowhere; modules are interpreted
Question 17
Fatal Error: Cannot open module file 'kinds.mod' almost always means:
- A. The module source has a syntax error
- B. kinds was not compiled before the file that uses it (wrong compile order or missing -I)
- C. The module is too large
- D. You must rewrite kinds as a submodule
Question 18
A circular module dependency (a uses b, b uses a):
- A. Compiles but runs slowly
- B. Cannot compile, because neither module can be compiled first
- C. Is required for mutual recursion
- D. Is fixed by adding implicit none
Question 19
For the heat-solver hierarchy (kinds; heat_solver and heat_io use kinds; heat uses all three),
a valid compile order is:
- A. heat, heat_io, heat_solver, kinds
- B. kinds, heat_solver, heat_io, heat
- C. heat_solver, kinds, heat, heat_io
- D. Any order works
Question 20
"Private by default, public on purpose" is recommended because: - A. It compiles faster - B. Helpers you add later stay hidden automatically, so you can only leak an internal by explicitly publishing it - C. It is required by the standard - D. It makes all variables constant
Answer Key
| Q | Ans | Why |
|---|---|---|
| 1 | B | A module packages shared definitions for use; it is not a runnable program. |
| 2 | B | only: imports named entities, documenting the dependency and avoiding clashes. |
| 3 | B | A module procedure is defined after the module's contains. |
| 4 | B | Bare private sets the default to hidden; expose with public ::. |
| 5 | B | The module gives callers the full signature, so the compiler checks each call. |
| 6 | D | Positional fixed scalars work with an implicit interface; the others need an explicit one. |
| 7 | B | A private name is invisible outside; only the module's procedures can change it. |
| 8 | B | Module variables have the save attribute implicitly and persist for the run. |
| 9 | B | A submodule supplies bodies for the parent's separate module procedures. |
| 10 | C | The module prefix marks a separate module procedure. |
| 11 | B | Submodules cut rebuild cascades; run-time code is unchanged. |
| 12 | B | A submodule sees its parent by host association. |
| 13 | B | Modules replaced COMMON, ideally with private state behind procedures. |
| 14 | B | COMMON overlays memory with no cross-routine type/length checking. |
| 15 | B | A .mod holds the interface, read by users at compile time. |
| 16 | B | The code is in the .o; the .mod is only the interface. |
| 17 | B | The .mod does not exist yet — a compile-order (or -I) problem. |
| 18 | B | Neither can be compiled first, so the cycle is rejected. |
| 19 | B | kinds first (uses nothing), heat last (uses all). |
| 20 | B | New helpers stay private unless you deliberately publish them. |
Topics to review by question
- Q1–3 → §8.1 (module,
use, module procedures). - Q4–8, 20 → §8.2 (public/private, explicit interfaces, module variables).
- Q9–12 → §8.3 (submodules).
- Q13–14 → §8.4 (why modules replaced
COMMON/INCLUDE). - Q15–19 → §8.5 (
.modfiles and compile order) and §8.6 (the hierarchy).
Scored below 16? Reread the flagged sections — modules underpin every chapter from here to the capstone, so this is the wrong place to have gaps.