Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

243 lines
11KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1987-2020 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation. A copy of
  7. the license is included in the
  8. section entitled "GNU Free Documentation License".
  9. This manual contains no Invariant Sections. The Front-Cover Texts are
  10. (a) (see below), and the Back-Cover Texts are (b) (see below).
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. <title>Initial processing (The C Preprocessor)</title>
  21. <meta name="description" content="Initial processing (The C Preprocessor)">
  22. <meta name="keywords" content="Initial processing (The C Preprocessor)">
  23. <meta name="resource-type" content="document">
  24. <meta name="distribution" content="global">
  25. <meta name="Generator" content="makeinfo">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Index-of-Directives.html#Index-of-Directives" rel="index" title="Index of Directives">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="Overview.html#Overview" rel="up" title="Overview">
  30. <link href="Tokenization.html#Tokenization" rel="next" title="Tokenization">
  31. <link href="Character-sets.html#Character-sets" rel="prev" title="Character sets">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.indentedblock {margin-right: 0em}
  36. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  37. blockquote.smallquotation {font-size: smaller}
  38. div.display {margin-left: 3.2em}
  39. div.example {margin-left: 3.2em}
  40. div.lisp {margin-left: 3.2em}
  41. div.smalldisplay {margin-left: 3.2em}
  42. div.smallexample {margin-left: 3.2em}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style: oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nolinebreak {white-space: nowrap}
  54. span.roman {font-family: initial; font-weight: normal}
  55. span.sansserif {font-family: sans-serif; font-weight: normal}
  56. ul.no-bullet {list-style: none}
  57. -->
  58. </style>
  59. </head>
  60. <body lang="en">
  61. <a name="Initial-processing"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Tokenization.html#Tokenization" accesskey="n" rel="next">Tokenization</a>, Previous: <a href="Character-sets.html#Character-sets" accesskey="p" rel="prev">Character sets</a>, Up: <a href="Overview.html#Overview" accesskey="u" rel="up">Overview</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index-of-Directives.html#Index-of-Directives" title="Index" rel="index">Index</a>]</p>
  65. </div>
  66. <hr>
  67. <a name="Initial-processing-1"></a>
  68. <h3 class="section">1.2 Initial processing</h3>
  69. <p>The preprocessor performs a series of textual transformations on its
  70. input. These happen before all other processing. Conceptually, they
  71. happen in a rigid order, and the entire file is run through each
  72. transformation before the next one begins. CPP actually does them
  73. all at once, for performance reasons. These transformations correspond
  74. roughly to the first three &ldquo;phases of translation&rdquo; described in the C
  75. standard.
  76. </p>
  77. <ol>
  78. <li> <a name="index-line-endings"></a>
  79. The input file is read into memory and broken into lines.
  80. <p>Different systems use different conventions to indicate the end of a
  81. line. GCC accepts the ASCII control sequences <kbd>LF</kbd>, <kbd>CR&nbsp;LF<!-- /@w --></kbd> and <kbd>CR</kbd> as end-of-line markers. These are the canonical
  82. sequences used by Unix, DOS and VMS, and the classic Mac OS (before
  83. OSX) respectively. You may therefore safely copy source code written
  84. on any of those systems to a different one and use it without
  85. conversion. (GCC may lose track of the current line number if a file
  86. doesn&rsquo;t consistently use one convention, as sometimes happens when it
  87. is edited on computers with different conventions that share a network
  88. file system.)
  89. </p>
  90. <p>If the last line of any input file lacks an end-of-line marker, the end
  91. of the file is considered to implicitly supply one. The C standard says
  92. that this condition provokes undefined behavior, so GCC will emit a
  93. warning message.
  94. </p>
  95. </li><li> <a name="index-trigraphs"></a>
  96. <a name="trigraphs"></a>If trigraphs are enabled, they are replaced by their
  97. corresponding single characters. By default GCC ignores trigraphs,
  98. but if you request a strictly conforming mode with the <samp>-std</samp>
  99. option, or you specify the <samp>-trigraphs</samp> option, then it
  100. converts them.
  101. <p>These are nine three-character sequences, all starting with &lsquo;<samp>??</samp>&rsquo;,
  102. that are defined by ISO C to stand for single characters. They permit
  103. obsolete systems that lack some of C&rsquo;s punctuation to use C. For
  104. example, &lsquo;<samp>??/</samp>&rsquo; stands for &lsquo;<samp>\</samp>&rsquo;, so <tt>'??/n'</tt> is a character
  105. constant for a newline.
  106. </p>
  107. <p>Trigraphs are not popular and many compilers implement them
  108. incorrectly. Portable code should not rely on trigraphs being either
  109. converted or ignored. With <samp>-Wtrigraphs</samp> GCC will warn you
  110. when a trigraph may change the meaning of your program if it were
  111. converted. See <a href="Invocation.html#Wtrigraphs">Wtrigraphs</a>.
  112. </p>
  113. <p>In a string constant, you can prevent a sequence of question marks
  114. from being confused with a trigraph by inserting a backslash between
  115. the question marks, or by separating the string literal at the
  116. trigraph and making use of string literal concatenation. <tt>&quot;(??\?)&quot;</tt>
  117. is the string &lsquo;<samp>(???)</samp>&rsquo;, not &lsquo;<samp>(?]</samp>&rsquo;. Traditional C compilers
  118. do not recognize these idioms.
  119. </p>
  120. <p>The nine trigraphs and their replacements are
  121. </p>
  122. <div class="smallexample">
  123. <pre class="smallexample">Trigraph: ??( ??) ??&lt; ??&gt; ??= ??/ ??' ??! ??-
  124. Replacement: [ ] { } # \ ^ | ~
  125. </pre></div>
  126. </li><li> <a name="index-continued-lines"></a>
  127. <a name="index-backslash_002dnewline"></a>
  128. Continued lines are merged into one long line.
  129. <p>A continued line is a line which ends with a backslash, &lsquo;<samp>\</samp>&rsquo;. The
  130. backslash is removed and the following line is joined with the current
  131. one. No space is inserted, so you may split a line anywhere, even in
  132. the middle of a word. (It is generally more readable to split lines
  133. only at white space.)
  134. </p>
  135. <p>The trailing backslash on a continued line is commonly referred to as a
  136. <em>backslash-newline</em>.
  137. </p>
  138. <p>If there is white space between a backslash and the end of a line, that
  139. is still a continued line. However, as this is usually the result of an
  140. editing mistake, and many compilers will not accept it as a continued
  141. line, GCC will warn you about it.
  142. </p>
  143. </li><li> <a name="index-comments"></a>
  144. <a name="index-line-comments"></a>
  145. <a name="index-block-comments"></a>
  146. All comments are replaced with single spaces.
  147. <p>There are two kinds of comments. <em>Block comments</em> begin with
  148. &lsquo;<samp>/*</samp>&rsquo; and continue until the next &lsquo;<samp>*/</samp>&rsquo;. Block comments do not
  149. nest:
  150. </p>
  151. <div class="smallexample">
  152. <pre class="smallexample">/* <span class="roman">this is</span> /* <span class="roman">one comment</span> */ <span class="roman">text outside comment</span>
  153. </pre></div>
  154. <p><em>Line comments</em> begin with &lsquo;<samp>//</samp>&rsquo; and continue to the end of the
  155. current line. Line comments do not nest either, but it does not matter,
  156. because they would end in the same place anyway.
  157. </p>
  158. <div class="smallexample">
  159. <pre class="smallexample">// <span class="roman">this is</span> // <span class="roman">one comment</span>
  160. <span class="roman">text outside comment</span>
  161. </pre></div>
  162. </li></ol>
  163. <p>It is safe to put line comments inside block comments, or vice versa.
  164. </p>
  165. <div class="smallexample">
  166. <pre class="smallexample">/* <span class="roman">block comment</span>
  167. // <span class="roman">contains line comment</span>
  168. <span class="roman">yet more comment</span>
  169. */ <span class="roman">outside comment</span>
  170. // <span class="roman">line comment</span> /* <span class="roman">contains block comment</span> */
  171. </pre></div>
  172. <p>But beware of commenting out one end of a block comment with a line
  173. comment.
  174. </p>
  175. <div class="smallexample">
  176. <pre class="smallexample"> // <span class="roman">l.c.</span> /* <span class="roman">block comment begins</span>
  177. <span class="roman">oops! this isn&rsquo;t a comment anymore</span> */
  178. </pre></div>
  179. <p>Comments are not recognized within string literals.
  180. <tt>&quot;/*&nbsp;blah&nbsp;*/&quot;<!-- /@w --></tt> is the string constant &lsquo;<samp>/*&nbsp;blah&nbsp;*/<!-- /@w --></samp>&rsquo;, not
  181. an empty string.
  182. </p>
  183. <p>Line comments are not in the 1989 edition of the C standard, but they
  184. are recognized by GCC as an extension. In C++ and in the 1999 edition
  185. of the C standard, they are an official part of the language.
  186. </p>
  187. <p>Since these transformations happen before all other processing, you can
  188. split a line mechanically with backslash-newline anywhere. You can
  189. comment out the end of a line. You can continue a line comment onto the
  190. next line with backslash-newline. You can even split &lsquo;<samp>/*</samp>&rsquo;,
  191. &lsquo;<samp>*/</samp>&rsquo;, and &lsquo;<samp>//</samp>&rsquo; onto multiple lines with backslash-newline.
  192. For example:
  193. </p>
  194. <div class="smallexample">
  195. <pre class="smallexample">/\
  196. *
  197. */ # /*
  198. */ defi\
  199. ne FO\
  200. O 10\
  201. 20
  202. </pre></div>
  203. <p>is equivalent to <code>#define&nbsp;FOO&nbsp;1020<!-- /@w --></code>. All these tricks are
  204. extremely confusing and should not be used in code intended to be
  205. readable.
  206. </p>
  207. <p>There is no way to prevent a backslash at the end of a line from being
  208. interpreted as a backslash-newline. This cannot affect any correct
  209. program, however.
  210. </p>
  211. <hr>
  212. <div class="header">
  213. <p>
  214. Next: <a href="Tokenization.html#Tokenization" accesskey="n" rel="next">Tokenization</a>, Previous: <a href="Character-sets.html#Character-sets" accesskey="p" rel="prev">Character sets</a>, Up: <a href="Overview.html#Overview" accesskey="u" rel="up">Overview</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index-of-Directives.html#Index-of-Directives" title="Index" rel="index">Index</a>]</p>
  215. </div>
  216. </body>
  217. </html>