Compilation Unit

What Does Compilation Unit Mean?

A compilation unit refers to a C source code which is compiled and treated as a single logical unit. It is generally one or more complete files; however, it also may be a certain part of a file if the #ifdef preprocessor directive is applied to choose specific code sections.


Definitions and declarations within the compilation unit establish the scope of data objects.

Techopedia Explains Compilation Unit

The compilation unit incorporates the files included using the #include preprocessor directive as part of it. However, it does not incorporate the source lines that are skipped due to the conditional inclusion preprocessor directives.

Compilation units are crucial to identify the scope of identifiers, and to determine the linkage of identifiers with other external and internal identifiers.

A compilation unit may relate to functions or data in other compilation units in the below given means:

  • A function in one compilation unit could very well call a function in a completely different compilation unit.
  • External linkage can be assigned to data objects to ensure that other compilation units can access them.

Programs comprised of more than a single compilation unit could be compiled individually, and then later linked to create the executable program. A legitimate C compilation unit includes no less than one external declaration.


Related Terms

Latest Privacy and Compliance Terms

Related Reading

Margaret Rouse

Margaret Rouse is an award-winning technical writer and teacher known for her ability to explain complex technical subjects to a non-technical, business audience. Over the past twenty years her explanations have appeared on TechTarget websites and she's been cited as an authority in articles by the New York Times, Time Magazine, USA Today, ZDNet, PC Magazine and Discovery Magazine.Margaret's idea of a fun day is helping IT and business professionals learn to speak each other’s highly specialized languages. If you have a suggestion for a new definition or how to improve a technical explanation, please email Margaret or contact her…