您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

186 行
9.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) 1988-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; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  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>C++ Interface (Using the GNU Compiler Collection (GCC))</title>
  21. <meta name="description" content="C++ Interface (Using the GNU Compiler Collection (GCC))">
  22. <meta name="keywords" content="C++ Interface (Using the GNU Compiler Collection (GCC))">
  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="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="C_002b_002b-Extensions.html#C_002b_002b-Extensions" rel="up" title="C++ Extensions">
  30. <link href="Template-Instantiation.html#Template-Instantiation" rel="next" title="Template Instantiation">
  31. <link href="Vague-Linkage.html#Vague-Linkage" rel="prev" title="Vague Linkage">
  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="C_002b_002b-Interface"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Template-Instantiation.html#Template-Instantiation" accesskey="n" rel="next">Template Instantiation</a>, Previous: <a href="Vague-Linkage.html#Vague-Linkage" accesskey="p" rel="prev">Vague Linkage</a>, Up: <a href="C_002b_002b-Extensions.html#C_002b_002b-Extensions" accesskey="u" rel="up">C++ Extensions</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  65. </div>
  66. <hr>
  67. <a name="C_002b_002b-Interface-and-Implementation-Pragmas"></a>
  68. <h3 class="section">7.4 C++ Interface and Implementation Pragmas</h3>
  69. <a name="index-interface-and-implementation-headers_002c-C_002b_002b"></a>
  70. <a name="index-C_002b_002b-interface-and-implementation-headers"></a>
  71. <a name="index-pragmas_002c-interface-and-implementation"></a>
  72. <p><code>#pragma interface</code> and <code>#pragma implementation</code> provide the
  73. user with a way of explicitly directing the compiler to emit entities
  74. with vague linkage (and debugging information) in a particular
  75. translation unit.
  76. </p>
  77. <p><em>Note:</em> These <code>#pragma</code>s have been superceded as of GCC 2.7.2
  78. by COMDAT support and the &ldquo;key method&rdquo; heuristic
  79. mentioned in <a href="Vague-Linkage.html#Vague-Linkage">Vague Linkage</a>. Using them can actually cause your
  80. program to grow due to unnecessary out-of-line copies of inline
  81. functions.
  82. </p>
  83. <dl compact="compact">
  84. <dt><code>#pragma interface</code></dt>
  85. <dt><code>#pragma interface &quot;<var>subdir</var>/<var>objects</var>.h&quot;</code></dt>
  86. <dd><a name="index-_0023pragma-interface"></a>
  87. <p>Use this directive in <em>header files</em> that define object classes, to save
  88. space in most of the object files that use those classes. Normally,
  89. local copies of certain information (backup copies of inline member
  90. functions, debugging information, and the internal tables that implement
  91. virtual functions) must be kept in each object file that includes class
  92. definitions. You can use this pragma to avoid such duplication. When a
  93. header file containing &lsquo;<samp>#pragma interface</samp>&rsquo; is included in a
  94. compilation, this auxiliary information is not generated (unless
  95. the main input source file itself uses &lsquo;<samp>#pragma implementation</samp>&rsquo;).
  96. Instead, the object files contain references to be resolved at link
  97. time.
  98. </p>
  99. <p>The second form of this directive is useful for the case where you have
  100. multiple headers with the same name in different directories. If you
  101. use this form, you must specify the same string to &lsquo;<samp>#pragma
  102. implementation</samp>&rsquo;.
  103. </p>
  104. </dd>
  105. <dt><code>#pragma implementation</code></dt>
  106. <dt><code>#pragma implementation &quot;<var>objects</var>.h&quot;</code></dt>
  107. <dd><a name="index-_0023pragma-implementation"></a>
  108. <p>Use this pragma in a <em>main input file</em>, when you want full output from
  109. included header files to be generated (and made globally visible). The
  110. included header file, in turn, should use &lsquo;<samp>#pragma interface</samp>&rsquo;.
  111. Backup copies of inline member functions, debugging information, and the
  112. internal tables used to implement virtual functions are all generated in
  113. implementation files.
  114. </p>
  115. <a name="index-implied-_0023pragma-implementation"></a>
  116. <a name="index-_0023pragma-implementation_002c-implied"></a>
  117. <a name="index-naming-convention_002c-implementation-headers"></a>
  118. <p>If you use &lsquo;<samp>#pragma implementation</samp>&rsquo; with no argument, it applies to
  119. an include file with the same basename<a name="DOCF4" href="#FOOT4"><sup>4</sup></a> as your source
  120. file. For example, in <samp>allclass.cc</samp>, giving just
  121. &lsquo;<samp>#pragma implementation</samp>&rsquo;
  122. by itself is equivalent to &lsquo;<samp>#pragma implementation &quot;allclass.h&quot;</samp>&rsquo;.
  123. </p>
  124. <p>Use the string argument if you want a single implementation file to
  125. include code from multiple header files. (You must also use
  126. &lsquo;<samp>#include</samp>&rsquo; to include the header file; &lsquo;<samp>#pragma
  127. implementation</samp>&rsquo; only specifies how to use the file&mdash;it doesn&rsquo;t actually
  128. include it.)
  129. </p>
  130. <p>There is no way to split up the contents of a single header file into
  131. multiple implementation files.
  132. </p></dd>
  133. </dl>
  134. <a name="index-inlining-and-C_002b_002b-pragmas"></a>
  135. <a name="index-C_002b_002b-pragmas_002c-effect-on-inlining"></a>
  136. <a name="index-pragmas-in-C_002b_002b_002c-effect-on-inlining"></a>
  137. <p>&lsquo;<samp>#pragma implementation</samp>&rsquo; and &lsquo;<samp>#pragma interface</samp>&rsquo; also have an
  138. effect on function inlining.
  139. </p>
  140. <p>If you define a class in a header file marked with &lsquo;<samp>#pragma
  141. interface</samp>&rsquo;, the effect on an inline function defined in that class is
  142. similar to an explicit <code>extern</code> declaration&mdash;the compiler emits
  143. no code at all to define an independent version of the function. Its
  144. definition is used only for inlining with its callers.
  145. </p>
  146. <a name="index-fno_002dimplement_002dinlines-1"></a>
  147. <p>Conversely, when you include the same header file in a main source file
  148. that declares it as &lsquo;<samp>#pragma implementation</samp>&rsquo;, the compiler emits
  149. code for the function itself; this defines a version of the function
  150. that can be found via pointers (or by callers compiled without
  151. inlining). If all calls to the function can be inlined, you can avoid
  152. emitting the function by compiling with <samp>-fno-implement-inlines</samp>.
  153. If any calls are not inlined, you will get linker errors.
  154. </p>
  155. <div class="footnote">
  156. <hr>
  157. <h4 class="footnotes-heading">Footnotes</h4>
  158. <h3><a name="FOOT4" href="#DOCF4">(4)</a></h3>
  159. <p>A file&rsquo;s <em>basename</em>
  160. is the name stripped of all leading path information and of trailing
  161. suffixes, such as &lsquo;<samp>.h</samp>&rsquo; or &lsquo;<samp>.C</samp>&rsquo; or &lsquo;<samp>.cc</samp>&rsquo;.</p>
  162. </div>
  163. <hr>
  164. <div class="header">
  165. <p>
  166. Next: <a href="Template-Instantiation.html#Template-Instantiation" accesskey="n" rel="next">Template Instantiation</a>, Previous: <a href="Vague-Linkage.html#Vague-Linkage" accesskey="p" rel="prev">Vague Linkage</a>, Up: <a href="C_002b_002b-Extensions.html#C_002b_002b-Extensions" accesskey="u" rel="up">C++ Extensions</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  167. </div>
  168. </body>
  169. </html>