A compilation unit is C source code that is compiled and
treated as one logical unit. The compilation unit is usually one
or more entire files, but can also be a selected portion of a file
if, for example, the
#ifdef preprocessor directive is
used to select specific code sections. Declarations and definitions
within a compilation unit determine the scope of functions and data
Files included by using the
directive become part of the compilation unit. Source lines skipped
because of the conditional inclusion preprocessor directives are not
included in the compilation unit.
Compilation units are important in determining the scope of identifiers, and in determining the linkage of identifiers to other internal and external identifiers. Section 2.3 discusses scope. Section 2.8 discusses linkage.
A compilation unit can refer to data or functions in other compilation units in the following ways:
Programs composed of more than one compilation unit can be separately compiled, and later linked to produce the executable program. A legal C compilation unit consists of at least one external declaration, as defined in Section 4.3.
A translation unit with no declarations is accepted with a compiler warning in all modes except for the strict ANSI standard mode.