You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 satır
7.3KB

  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>Overview (The C Preprocessor)</title>
  21. <meta name="description" content="Overview (The C Preprocessor)">
  22. <meta name="keywords" content="Overview (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="index.html#Top" rel="up" title="Top">
  30. <link href="Character-sets.html#Character-sets" rel="next" title="Character sets">
  31. <link href="index.html#Top" rel="prev" title="Top">
  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="Overview"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Header-Files.html#Header-Files" accesskey="n" rel="next">Header Files</a>, Previous: <a href="index.html#Top" accesskey="p" rel="prev">Top</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</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="Overview-1"></a>
  68. <h2 class="chapter">1 Overview</h2>
  69. <p>The C preprocessor, often known as <em>cpp</em>, is a <em>macro processor</em>
  70. that is used automatically by the C compiler to transform your program
  71. before compilation. It is called a macro processor because it allows
  72. you to define <em>macros</em>, which are brief abbreviations for longer
  73. constructs.
  74. </p>
  75. <p>The C preprocessor is intended to be used only with C, C++, and
  76. Objective-C source code. In the past, it has been abused as a general
  77. text processor. It will choke on input which does not obey C&rsquo;s lexical
  78. rules. For example, apostrophes will be interpreted as the beginning of
  79. character constants, and cause errors. Also, you cannot rely on it
  80. preserving characteristics of the input which are not significant to
  81. C-family languages. If a Makefile is preprocessed, all the hard tabs
  82. will be removed, and the Makefile will not work.
  83. </p>
  84. <p>Having said that, you can often get away with using cpp on things which
  85. are not C. Other Algol-ish programming languages are often safe
  86. (Ada, etc.) So is assembly, with caution. <samp>-traditional-cpp</samp>
  87. mode preserves more white space, and is otherwise more permissive. Many
  88. of the problems can be avoided by writing C or C++ style comments
  89. instead of native language comments, and keeping macros simple.
  90. </p>
  91. <p>Wherever possible, you should use a preprocessor geared to the language
  92. you are writing in. Modern versions of the GNU assembler have macro
  93. facilities. Most high level programming languages have their own
  94. conditional compilation and inclusion mechanism. If all else fails,
  95. try a true general text processor, such as GNU M4.
  96. </p>
  97. <p>C preprocessors vary in some details. This manual discusses the GNU C
  98. preprocessor, which provides a small superset of the features of ISO
  99. Standard C. In its default mode, the GNU C preprocessor does not do a
  100. few things required by the standard. These are features which are
  101. rarely, if ever, used, and may cause surprising changes to the meaning
  102. of a program which does not expect them. To get strict ISO Standard C,
  103. you should use the <samp>-std=c90</samp>, <samp>-std=c99</samp>,
  104. <samp>-std=c11</samp> or <samp>-std=c17</samp> options, depending
  105. on which version of the standard you want. To get all the mandatory
  106. diagnostics, you must also use <samp>-pedantic</samp>. See <a href="Invocation.html#Invocation">Invocation</a>.
  107. </p>
  108. <p>This manual describes the behavior of the ISO preprocessor. To
  109. minimize gratuitous differences, where the ISO preprocessor&rsquo;s
  110. behavior does not conflict with traditional semantics, the
  111. traditional preprocessor should behave the same way. The various
  112. differences that do exist are detailed in the section <a href="Traditional-Mode.html#Traditional-Mode">Traditional Mode</a>.
  113. </p>
  114. <p>For clarity, unless noted otherwise, references to &lsquo;<samp>CPP</samp>&rsquo; in this
  115. manual refer to GNU CPP.
  116. </p>
  117. <table class="menu" border="0" cellspacing="0">
  118. <tr><td align="left" valign="top">&bull; <a href="Character-sets.html#Character-sets" accesskey="1">Character sets</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  119. </td></tr>
  120. <tr><td align="left" valign="top">&bull; <a href="Initial-processing.html#Initial-processing" accesskey="2">Initial processing</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  121. </td></tr>
  122. <tr><td align="left" valign="top">&bull; <a href="Tokenization.html#Tokenization" accesskey="3">Tokenization</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  123. </td></tr>
  124. <tr><td align="left" valign="top">&bull; <a href="The-preprocessing-language.html#The-preprocessing-language" accesskey="4">The preprocessing language</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  125. </td></tr>
  126. </table>
  127. <hr>
  128. <div class="header">
  129. <p>
  130. Next: <a href="Header-Files.html#Header-Files" accesskey="n" rel="next">Header Files</a>, Previous: <a href="index.html#Top" accesskey="p" rel="prev">Top</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</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>
  131. </div>
  132. </body>
  133. </html>