Compilation Unit

Why Trust Techopedia

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

Margaret Rouse
Senior Editor
Margaret Rouse
Senior Editor

Margaret 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 IT definitions have been published by Que in an encyclopedia of technology terms and cited in articles by the New York Times, Time Magazine, USA Today, ZDNet, PC Magazine, and Discovery Magazine. She joined Techopedia in 2011. Margaret's idea of a fun day is helping IT and business professionals learn to speak each other’s highly specialized languages.