include_directive
Snippet from Wikipedia: 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 Go, Python and Haskell support modularization via an import statement, which makes the compiler/interpreter load a module, resolving code through the linked module; not by including text. Compiled languages, such as Rust and D, simply link all object files at compile time. Similarly, C++ also introduced import to import C++ modules, which uses .pcm files to store as intermediates similar to how precompiled headers work. Although Java has import and C# has using, these are not the same as an include directive. In fact, in these languages, classes are loaded on demand by a class loader, and can be accessed simply by fully qualifying the class with its namespaces. The import statements in these languages are used only to add a class to the current scope.

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

include_directive.txt · Last modified: 2025/02/01 06:51 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki