Include directive

An include directive instructs a text file processor to replace the directive text with the content of a specified file.

The act of including may be logical in nature. The processor may simply process the include file content at the location of the directive without creating a combined file.

Different processors may use different syntax. The C preprocessor (used with C, C++ and in other contexts) defines an include directive as a line that starts #include and is followed by a file specification. COBOL defines an include directive indicated by copy in order to include a copybook.

Generally, for C/C++ the include directive is used to include a header file, but can include any file. Although relatively uncommon, it is sometimes used to include a body file such as a .c file.

The include directive can support encapsulation and reuse. Different parts of a system can be segregated into logical groupings yet rely on one another via file inclusion. C and C++ are designed to leverage include while also optimizing build time by allowing declaration separate from implementation. The included information can be minimized to only declarations.

As directly including file content has significant drawbacks, such as excessive boilerplate or type/language syntax unawareness, newer languages have been designed without an include directive. Languages such as Java and C# support modularization via an import concept that allows a package or module to use the assets of another module at a conceptual level by loading the associated Java class file or C# DLL as necessary; not by including text. Compiled languages, such as Rust and D, simply link all object files at compile time, and C++ also introduced import to import modules.

Although C# has the ability to use some preprocessor directives similar to those of the C preprocessor, it does not contain the #include directive.


© MMXXIII Rich X Search. We shall prevail. All rights reserved. Rich X Search