summaryrefslogtreecommitdiff
path: root/devdocs/c/preprocessor.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/c/preprocessor.html')
-rw-r--r--devdocs/c/preprocessor.html36
1 files changed, 36 insertions, 0 deletions
diff --git a/devdocs/c/preprocessor.html b/devdocs/c/preprocessor.html
new file mode 100644
index 00000000..1300711b
--- /dev/null
+++ b/devdocs/c/preprocessor.html
@@ -0,0 +1,36 @@
+ <h1 id="firstHeading" class="firstHeading">Preprocessor</h1> <p>The preprocessor is executed at <a href="language/translation_phases" title="c/language/translation phases">translation phase 4</a>, before the compilation. The result of preprocessing is a single file which is then passed to the actual compiler.</p>
+<h3 id="Directives"> Directives</h3> <p>The preprocessing directives control the behavior of the preprocessor. Each directive occupies one line and has the following format:</p>
+<ul>
+<li> <code>#</code> character </li>
+<li> preprocessing instruction (one of <code>define</code>, <code>undef</code>, <code>include</code>, <code>if</code>, <code>ifdef</code>, <code>ifndef</code>, <code>else</code>, <code>elif</code><span class="t-rev-inl t-since-c23"><span>, <code>elifdef</code>, <code>elifndef</code></span><span><span class="t-mark-rev t-since-c23">(since C23)</span></span></span>, <code>endif</code>, <code>line</code><span class="t-rev-inl t-since-c23"><span>, <code>embed</code></span><span><span class="t-mark-rev t-since-c23">(since C23)</span></span></span>, <code>error</code><span class="t-rev-inl t-since-c23"><span>, <code>warning</code></span><span><span class="t-mark-rev t-since-c23">(since C23)</span></span></span>, <code>pragma</code>) <sup id="cite_ref-1" class="reference"><a href="#cite_note-1">[1]</a></sup> </li>
+<li> arguments (depends on the instruction) </li>
+<li> line break </li>
+</ul> <p>The null directive (<code>#</code> followed by a line break) is allowed and has no effect.</p>
+<h3 id="Capabilities"> Capabilities</h3> <p>The preprocessor has the source file translation capabilities:</p>
+<ul>
+<li> <b><a href="preprocessor/conditional" title="c/preprocessor/conditional"> conditionally</a></b> compile of parts of source file (controlled by directive <code>#if</code>, <code>#ifdef</code>, <code>#ifndef</code>, <code>#else</code>, <code>#elif</code><span class="t-rev-inl t-since-c23"><span>, <code>#elifdef</code>, <code>#elifndef</code></span><span><span class="t-mark-rev t-since-c23">(since C23)</span></span></span> and <code>#endif</code>). </li>
+<li> <b><a href="preprocessor/replace" title="c/preprocessor/replace"> replace</a></b> text macros while possibly concatenating or quoting identifiers (controlled by directives <code>#define</code> and <code>#undef</code>, and operators <code>#</code> and <code>##</code>) </li>
+<li> <b><a href="preprocessor/include" title="c/preprocessor/include">include</a></b> other files (controlled by directive <code>#include</code> <span class="t-rev-inl t-since-c23"><span>and checked with <code>__has_include</code></span><span><span class="t-mark-rev t-since-c23">(since C23)</span></span></span>) </li>
+<li> cause an <b><a href="preprocessor/error" title="c/preprocessor/error">error</a></b> <span class="t-rev-inl t-since-c23"><span>or <b><a href="preprocessor/error" title="c/preprocessor/error">warning</a></b></span><span><span class="t-mark-rev t-since-c23">(since C23)</span></span></span> (controlled by directive <code>#error</code><span class="t-rev-inl t-since-c23"><span> or <code>#warning</code> respectively</span><span><span class="t-mark-rev t-since-c23">(since C23)</span></span></span>) </li>
+</ul> <p>The following aspects of the preprocessor can be controlled:</p>
+<ul>
+<li> <b><a href="preprocessor/impl" title="c/preprocessor/impl"> implementation defined</a></b> behavior (controlled by directive <code>#pragma</code><span class="t-rev-inl t-since-c99"><span> and operator <code>_Pragma</code></span><span><span class="t-mark-rev t-since-c99">(since C99)</span></span></span>) </li>
+<li> <b><a href="preprocessor/line" title="c/preprocessor/line"> file name and line information</a></b> available to the preprocessor (controlled by directives <code>#line</code>) </li>
+</ul> <h3 id="Footnotes"> Footnotes</h3> <ol class="references"> <li id="cite_note-1"> <span class="reference-text">These are the directives defined by the standard. The standard does not define behavior for other directives: they might be ignored, have some useful meaning, or make the program ill-formed. Even if otherwise ignored, they are removed from the source code when the preprocessor is done. <span class="t-rev-inl t-until-c23"><span>A common non-standard extension is the directive <code>#warning</code> which emits a user-defined message during compilation.</span><span><span class="t-mark-rev t-until-c23">(until C23)</span></span></span></span> </li> </ol> <h3 id="References"> References</h3> <ul>
+<li> C17 standard (ISO/IEC 9899:2018): </li>
+<ul><li> 6.10 Preprocessing directives (p: 117-129) </li></ul>
+<li> C11 standard (ISO/IEC 9899:2011): </li>
+<ul><li> 6.10 Preprocessing directives (p: 160-178) </li></ul>
+<li> C99 standard (ISO/IEC 9899:1999): </li>
+<ul><li> 6.10 Preprocessing directives (p: 145-162) </li></ul>
+<li> C89/C90 standard (ISO/IEC 9899:1990): </li>
+<ul><li> 3.8 PREPROCESSING DIRECTIVES </li></ul>
+</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td colspan="2"> <span><a href="preprocessor/replace#Predefined_macros" title="c/preprocessor/replace">C documentation</a></span> for <span class=""><span>Predefined Macro Symbols</span></span> </td>
+</tr> <tr class="t-dsc"> <td colspan="2"> <span><a href="symbol_index/macro" title="c/symbol index/macro">C documentation</a></span> for <span class=""><span>Macro Symbol Index</span></span> </td>
+</tr> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/preprocessor" title="cpp/preprocessor">C++ documentation</a></span> for <span class=""><span>Preprocessor</span></span> </td>
+</tr> </table> <div class="_attribution">
+ <p class="_attribution-p">
+ &copy; cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br>
+ <a href="https://en.cppreference.com/w/c/preprocessor" class="_attribution-link">https://en.cppreference.com/w/c/preprocessor</a>
+ </p>
+</div>