Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
C preprocessor
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==== Code inclusion ==== To include the content of one file into another, the preprocessor replaces a line that starts with <code>#include</code> with the content of the file specified after the directive. The inclusion may be logical in the sense that the resulting content may not be stored on disk and certainly is not overwritten to the source file. The file being included need not contain any sort of code, as this directive will copy the contents of whatever file is included in-place, but the most typical use of <code>#include</code> is to include a header file (or in some rarer cases, a source file). In the following example code, the preprocessor replaces the line <code>#include <stdio.h></code> with the content of the standard library header file named 'stdio.h' in which the [[Function (computer programming)|function]] <code>printf()</code> and other symbols are declared. <syntaxhighlight lang="cpp"> #include <stdio.h> int main(void) { printf("Hello, World!\n"); return 0; } </syntaxhighlight> In this case, the file name is enclosed in angle brackets to denote that it is a system file. For a file in the [[codebase]] being [[software build|built]], double-quotes are used instead. The preprocessor may use a different search algorithm to find the file based on this distinction. For C, a header file is usually named with a <code>.h</code> extension. In C++, the convention for file extension varies with common extensions <code>.h</code> and <code>.hpp</code>. But the preprocessor includes a file regardless of the extension. In fact, sometimes code includes <code>.c</code> or <code>.cpp</code> files. To prevent including the same file multiple times which often leads to a compiler error, a header file typically contains an [[include guard|{{mono|#include}} guard]] or if supported by the preprocessor [[pragma once|{{mono|#pragma once}}]] to prevent multiple inclusion.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)