翻訳単位とは?
翻訳単位は、ソースファイルを取り、そのインクルードされたすべてのヘッダーとマクロを展開して形成される、コンパイラが一度に処理するソースコードの完全な本体です。コンパイラはこの展開されたテキストを1つの独立した単位として扱い、そこから1つのオブジェクトファイルを出力します。各翻訳単位は個別にコンパイルされ、後でリンカによってのみ結合されます。
なぜ重要か
翻訳単位はコンパイラがコードを見る粒度であり、そのために宣言と定義はその中で可視でなければなりません。その境界は、増分再ビルドの挙動と、インクルードに関連する多くのエラーの両方を説明します。
関連ガイド
What Is an Object File?An object file holds machine code and data for one compiled translation unit, with unresolved references the…
What Is a Preprocessor Directive?A preprocessor directive is an instruction handled before compilation that includes files, defines macros, or…
What Is a Header Guard?A header guard is a preprocessor pattern that ensures a header file is included only once per translation uni…