Overview.html 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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-2023 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.7, 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" rel="start" title="Top">
  27. <link href="Index-of-Directives.html" rel="index" title="Index of Directives">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="index.html" rel="up" title="Top">
  30. <link href="Character-sets.html" rel="next" title="Character sets">
  31. <link href="index.html" rel="prev" title="Top">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.indentedblock {margin-right: 0em}
  36. div.display {margin-left: 3.2em}
  37. div.example {margin-left: 3.2em}
  38. div.lisp {margin-left: 3.2em}
  39. kbd {font-style: oblique}
  40. pre.display {font-family: inherit}
  41. pre.format {font-family: inherit}
  42. pre.menu-comment {font-family: serif}
  43. pre.menu-preformatted {font-family: serif}
  44. span.nolinebreak {white-space: nowrap}
  45. span.roman {font-family: initial; font-weight: normal}
  46. span.sansserif {font-family: sans-serif; font-weight: normal}
  47. ul.no-bullet {list-style: none}
  48. -->
  49. </style>
  50. </head>
  51. <body lang="en">
  52. <span id="Overview"></span><div class="header">
  53. <p>
  54. Next: <a href="Header-Files.html" accesskey="n" rel="next">Header Files</a>, Previous: <a href="index.html" accesskey="p" rel="prev">Top</a>, Up: <a href="index.html" 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" title="Index" rel="index">Index</a>]</p>
  55. </div>
  56. <hr>
  57. <span id="Overview-1"></span><h2 class="chapter">1 Overview</h2>
  58. <p>The C preprocessor, often known as <em>cpp</em>, is a <em>macro processor</em>
  59. that is used automatically by the C compiler to transform your program
  60. before compilation. It is called a macro processor because it allows
  61. you to define <em>macros</em>, which are brief abbreviations for longer
  62. constructs.
  63. </p>
  64. <p>The C preprocessor is intended to be used only with C, C++, and
  65. Objective-C source code. In the past, it has been abused as a general
  66. text processor. It will choke on input which does not obey C&rsquo;s lexical
  67. rules. For example, apostrophes will be interpreted as the beginning of
  68. character constants, and cause errors. Also, you cannot rely on it
  69. preserving characteristics of the input which are not significant to
  70. C-family languages. If a Makefile is preprocessed, all the hard tabs
  71. will be removed, and the Makefile will not work.
  72. </p>
  73. <p>Having said that, you can often get away with using cpp on things which
  74. are not C. Other Algol-ish programming languages are often safe
  75. (Ada, etc.) So is assembly, with caution. <samp>-traditional-cpp</samp>
  76. mode preserves more white space, and is otherwise more permissive. Many
  77. of the problems can be avoided by writing C or C++ style comments
  78. instead of native language comments, and keeping macros simple.
  79. </p>
  80. <p>Wherever possible, you should use a preprocessor geared to the language
  81. you are writing in. Modern versions of the GNU assembler have macro
  82. facilities. Most high level programming languages have their own
  83. conditional compilation and inclusion mechanism. If all else fails,
  84. try a true general text processor, such as GNU M4.
  85. </p>
  86. <p>C preprocessors vary in some details. This manual discusses the GNU C
  87. preprocessor, which provides a small superset of the features of ISO
  88. Standard C. In its default mode, the GNU C preprocessor does not do a
  89. few things required by the standard. These are features which are
  90. rarely, if ever, used, and may cause surprising changes to the meaning
  91. of a program which does not expect them. To get strict ISO Standard C,
  92. you should use the <samp>-std=c90</samp>, <samp>-std=c99</samp>,
  93. <samp>-std=c11</samp> or <samp>-std=c17</samp> options, depending
  94. on which version of the standard you want. To get all the mandatory
  95. diagnostics, you must also use <samp>-pedantic</samp>. See <a href="Invocation.html">Invocation</a>.
  96. </p>
  97. <p>This manual describes the behavior of the ISO preprocessor. To
  98. minimize gratuitous differences, where the ISO preprocessor&rsquo;s
  99. behavior does not conflict with traditional semantics, the
  100. traditional preprocessor should behave the same way. The various
  101. differences that do exist are detailed in the section <a href="Traditional-Mode.html">Traditional Mode</a>.
  102. </p>
  103. <p>For clarity, unless noted otherwise, references to &lsquo;<samp>CPP</samp>&rsquo; in this
  104. manual refer to GNU CPP.
  105. </p>
  106. <table class="menu" border="0" cellspacing="0">
  107. <tr><td align="left" valign="top">&bull; <a href="Character-sets.html" accesskey="1">Character sets</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  108. </td></tr>
  109. <tr><td align="left" valign="top">&bull; <a href="Initial-processing.html" accesskey="2">Initial processing</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  110. </td></tr>
  111. <tr><td align="left" valign="top">&bull; <a href="Tokenization.html" accesskey="3">Tokenization</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  112. </td></tr>
  113. <tr><td align="left" valign="top">&bull; <a href="The-preprocessing-language.html" accesskey="4">The preprocessing language</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  114. </td></tr>
  115. </table>
  116. <hr>
  117. <div class="header">
  118. <p>
  119. Next: <a href="Header-Files.html" accesskey="n" rel="next">Header Files</a>, Previous: <a href="index.html" accesskey="p" rel="prev">Top</a>, Up: <a href="index.html" 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" title="Index" rel="index">Index</a>]</p>
  120. </div>
  121. </body>
  122. </html>