Skeleton descriptions are typeset in italic text, so please don't remove these descriptions when editing the topic.
Provides a short natural language abstract of the module’s contents. Specifies the different levels of teaching.
This module outlines the issues involved in using separate compilation on multiple program files.
Level Objective
Foundational: Awareness of the existence of separate compilation
Main: Awareness of supporting mechanisms and tools
Advanced: Awareness of technicalities and tools
Why is this important? Why do we want to learn/teach this topic?
Any non-trivial program will span more than one source file. This makes separate compilation necessary. Separate compilation also leads to quick build times in projects under development.
Very brief introduction to the topic.
A student:
- needs to have the text editor skills to split a single-file program into multiple files.
- needs to be able to split function and classes into their declaration and definition. [C++ object model: declarations] [C++ object model: Definitions]
A list of things "a student should be able to" after the curriculum. The next word should be an action word and testable in an exam. Max 5 items.
A student should be able to:
- split a single file program into main, one or more auxiliaries, and header files (or modules), all in one directory
- compile and link a program that is spread over multiple files (again, all in one directory), either on the commandline or with a build system.
- describe the functions of the various files involved: source, object, executable.
- Necessity of having function be declared at the locus of use
- Solving this by explicit declaration or by using header files.
This section mentions subtle points to understand, like anything resulting in implementation-defined, unspecified, or undefined behavior.
- Explain differences (including in desirability) between having explicit declarations of functions in the main program versus using header files or modules.
- Compilation on a single commandline versus multiple. Resolution order when linking.
- What needs to be recompiled if only a function is altered? Altered in use syntax versus altered only in semantics.
- All of the above.
A student should be able to:
- Use compile flags, including
-Iand-Lto specify search paths. - Make header files for their own code, including using header guards.
- Use include directives for the headers of external libraries.
- Be able to declare
externvariables.
- Build systems make things both easier and harder.
- Cover the mechanisms for include and library paths to your own code, as well as discovery mechanisms for external libraries.
These are important topics that are not expected to be covered but provide guidance where one can continue to investigate this topic in more depth.
- Language inter-operability: the
extern "C"mechanism. - Linker conventions including name mangling.
- The
nmtool for inspection object files and libraries, including de-mangling. - Understand the issues involved in deciding between include guards and
#pragma once.