選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

154 行
6.9KB

  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>The preprocessing language (The C Preprocessor)</title>
  21. <meta name="description" content="The preprocessing language (The C Preprocessor)">
  22. <meta name="keywords" content="The preprocessing language (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="Header-Files.html#Header-Files" rel="next" title="Header Files">
  31. <link href="Tokenization.html#Tokenization" rel="prev" title="Tokenization">
  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="The-preprocessing-language"></a>
  62. <div class="header">
  63. <p>
  64. Previous: <a href="Tokenization.html#Tokenization" accesskey="p" rel="prev">Tokenization</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="The-preprocessing-language-1"></a>
  68. <h3 class="section">1.4 The preprocessing language</h3>
  69. <a name="index-directives"></a>
  70. <a name="index-preprocessing-directives"></a>
  71. <a name="index-directive-line"></a>
  72. <a name="index-directive-name"></a>
  73. <p>After tokenization, the stream of tokens may simply be passed straight
  74. to the compiler&rsquo;s parser. However, if it contains any operations in the
  75. <em>preprocessing language</em>, it will be transformed first. This stage
  76. corresponds roughly to the standard&rsquo;s &ldquo;translation phase 4&rdquo; and is
  77. what most people think of as the preprocessor&rsquo;s job.
  78. </p>
  79. <p>The preprocessing language consists of <em>directives</em> to be executed
  80. and <em>macros</em> to be expanded. Its primary capabilities are:
  81. </p>
  82. <ul>
  83. <li> Inclusion of header files. These are files of declarations that can be
  84. substituted into your program.
  85. </li><li> Macro expansion. You can define <em>macros</em>, which are abbreviations
  86. for arbitrary fragments of C code. The preprocessor will replace the
  87. macros with their definitions throughout the program. Some macros are
  88. automatically defined for you.
  89. </li><li> Conditional compilation. You can include or exclude parts of the
  90. program according to various conditions.
  91. </li><li> Line control. If you use a program to combine or rearrange source files
  92. into an intermediate file which is then compiled, you can use line
  93. control to inform the compiler where each source line originally came
  94. from.
  95. </li><li> Diagnostics. You can detect problems at compile time and issue errors
  96. or warnings.
  97. </li></ul>
  98. <p>There are a few more, less useful, features.
  99. </p>
  100. <p>Except for expansion of predefined macros, all these operations are
  101. triggered with <em>preprocessing directives</em>. Preprocessing directives
  102. are lines in your program that start with &lsquo;<samp>#</samp>&rsquo;. Whitespace is
  103. allowed before and after the &lsquo;<samp>#</samp>&rsquo;. The &lsquo;<samp>#</samp>&rsquo; is followed by an
  104. identifier, the <em>directive name</em>. It specifies the operation to
  105. perform. Directives are commonly referred to as &lsquo;<samp>#<var>name</var></samp>&rsquo;
  106. where <var>name</var> is the directive name. For example, &lsquo;<samp>#define</samp>&rsquo; is
  107. the directive that defines a macro.
  108. </p>
  109. <p>The &lsquo;<samp>#</samp>&rsquo; which begins a directive cannot come from a macro
  110. expansion. Also, the directive name is not macro expanded. Thus, if
  111. <code>foo</code> is defined as a macro expanding to <code>define</code>, that does
  112. not make &lsquo;<samp>#foo</samp>&rsquo; a valid preprocessing directive.
  113. </p>
  114. <p>The set of valid directive names is fixed. Programs cannot define new
  115. preprocessing directives.
  116. </p>
  117. <p>Some directives require arguments; these make up the rest of the
  118. directive line and must be separated from the directive name by
  119. whitespace. For example, &lsquo;<samp>#define</samp>&rsquo; must be followed by a macro
  120. name and the intended expansion of the macro.
  121. </p>
  122. <p>A preprocessing directive cannot cover more than one line. The line
  123. may, however, be continued with backslash-newline, or by a block comment
  124. which extends past the end of the line. In either case, when the
  125. directive is processed, the continuations have already been merged with
  126. the first line to make one long line.
  127. </p>
  128. <hr>
  129. <div class="header">
  130. <p>
  131. Previous: <a href="Tokenization.html#Tokenization" accesskey="p" rel="prev">Tokenization</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>
  132. </div>
  133. </body>
  134. </html>