C++: Overview and Toolchain¶
C++ is a statically typed, compiled language standardized by ISO. It supports value-oriented, procedural, object-oriented, generic, and functional styles and gives programs direct control over representation and resource lifetime.
This track uses C++20 as the executable baseline. Later standards may add facilities, but their availability depends on compiler and library support. The official status page distinguishes published standards from ongoing work.
Learning objectives¶
- distinguish preprocessing, compilation, linking, and execution;
- reason about values, references, lifetimes, and ownership;
- use RAII rather than manual cleanup paths;
- understand copy/move behavior and generic constraints;
- select standard containers and algorithms from their contracts; and
- write concurrent code without data races.
A first program¶
In a hosted implementation, main is the designated entry function. Reaching
its closing brace returns zero. std::cout is a standard-library stream made
available through <iostream>.
Translation model¶
A simplified pipeline is:
- preprocessing handles directives such as
#includeand conditional compilation; - compilation checks language rules and produces an object file;
- linking resolves definitions across object files and libraries;
- the environment loads and begins executing the program.
A translation unit is roughly one source file after preprocessing. A declaration introduces a name and type; a definition also supplies the entity. The One Definition Rule controls which entities require one program-wide definition and which identical definitions may occur across translation units.
Diagnostics and behavior categories¶
- ill-formed, diagnostic required: the implementation must issue at least one diagnostic;
- ill-formed, no diagnostic required: the program is invalid, but a diagnostic is not required;
- implementation-defined: the implementation chooses and documents one behavior;
- unspecified: one of several permitted behaviors occurs without a documentation requirement;
- undefined behavior: the standard imposes no requirements on the execution.
Undefined behavior is not an exception mechanism. A program appearing to work in one build does not make an out-of-bounds access, invalid lifetime use, or data race valid.
Baseline build¶
Warnings are implementation-specific and do not prove correctness, but treating reviewed warnings as errors helps prevent known defect classes. Release builds, debug information, sanitizers, and optimization should be separate intentional configurations.
Sequence¶
Continue with types, values, and references, then RAII and resource management before using owning pointers directly.