| <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| <html> |
| <!-- Copyright (C) 1988-2015 Free Software Foundation, Inc. |
| |
| Permission is granted to copy, distribute and/or modify this document |
| under the terms of the GNU Free Documentation License, Version 1.3 or |
| any later version published by the Free Software Foundation; with the |
| Invariant Sections being "Funding Free Software", the Front-Cover |
| Texts being (a) (see below), and with the Back-Cover Texts being (b) |
| (see below). A copy of the license is included in the section entitled |
| "GNU Free Documentation License". |
| |
| (a) The FSF's Front-Cover Text is: |
| |
| A GNU Manual |
| |
| (b) The FSF's Back-Cover Text is: |
| |
| You have freedom to copy and modify this GNU Manual, like GNU |
| software. Copies published by the Free Software Foundation raise |
| funds for GNU development. --> |
| <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ --> |
| <head> |
| <title>Using the GNU Compiler Collection (GCC): C++ Interface</title> |
| |
| <meta name="description" content="Using the GNU Compiler Collection (GCC): C++ Interface"> |
| <meta name="keywords" content="Using the GNU Compiler Collection (GCC): C++ Interface"> |
| <meta name="resource-type" content="document"> |
| <meta name="distribution" content="global"> |
| <meta name="Generator" content="makeinfo"> |
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| <link href="index.html#Top" rel="start" title="Top"> |
| <link href="Option-Index.html#Option-Index" rel="index" title="Option Index"> |
| <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> |
| <link href="C_002b_002b-Extensions.html#C_002b_002b-Extensions" rel="up" title="C++ Extensions"> |
| <link href="Template-Instantiation.html#Template-Instantiation" rel="next" title="Template Instantiation"> |
| <link href="Vague-Linkage.html#Vague-Linkage" rel="prev" title="Vague Linkage"> |
| <style type="text/css"> |
| <!-- |
| a.summary-letter {text-decoration: none} |
| blockquote.smallquotation {font-size: smaller} |
| div.display {margin-left: 3.2em} |
| div.example {margin-left: 3.2em} |
| div.indentedblock {margin-left: 3.2em} |
| div.lisp {margin-left: 3.2em} |
| div.smalldisplay {margin-left: 3.2em} |
| div.smallexample {margin-left: 3.2em} |
| div.smallindentedblock {margin-left: 3.2em; font-size: smaller} |
| div.smalllisp {margin-left: 3.2em} |
| kbd {font-style:oblique} |
| pre.display {font-family: inherit} |
| pre.format {font-family: inherit} |
| pre.menu-comment {font-family: serif} |
| pre.menu-preformatted {font-family: serif} |
| pre.smalldisplay {font-family: inherit; font-size: smaller} |
| pre.smallexample {font-size: smaller} |
| pre.smallformat {font-family: inherit; font-size: smaller} |
| pre.smalllisp {font-size: smaller} |
| span.nocodebreak {white-space:nowrap} |
| span.nolinebreak {white-space:nowrap} |
| span.roman {font-family:serif; font-weight:normal} |
| span.sansserif {font-family:sans-serif; font-weight:normal} |
| ul.no-bullet {list-style: none} |
| --> |
| </style> |
| |
| |
| </head> |
| |
| <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> |
| <a name="C_002b_002b-Interface"></a> |
| <div class="header"> |
| <p> |
| 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> [<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> |
| </div> |
| <hr> |
| <a name="g_t_0023pragma-interface-and-implementation"></a> |
| <h3 class="section">7.4 #pragma interface and implementation</h3> |
| |
| <a name="index-interface-and-implementation-headers_002c-C_002b_002b"></a> |
| <a name="index-C_002b_002b-interface-and-implementation-headers"></a> |
| <a name="index-pragmas_002c-interface-and-implementation"></a> |
| |
| <p><code>#pragma interface</code> and <code>#pragma implementation</code> provide the |
| user with a way of explicitly directing the compiler to emit entities |
| with vague linkage (and debugging information) in a particular |
| translation unit. |
| </p> |
| <p><em>Note:</em> As of GCC 2.7.2, these <code>#pragma</code>s are not useful in |
| most cases, because of COMDAT support and the “key method” heuristic |
| mentioned in <a href="Vague-Linkage.html#Vague-Linkage">Vague Linkage</a>. Using them can actually cause your |
| program to grow due to unnecessary out-of-line copies of inline |
| functions. Currently (3.4) the only benefit of these |
| <code>#pragma</code>s is reduced duplication of debugging information, and |
| that should be addressed soon on DWARF 2 targets with the use of |
| COMDAT groups. |
| </p> |
| <dl compact="compact"> |
| <dt><code>#pragma interface</code></dt> |
| <dt><code>#pragma interface "<var>subdir</var>/<var>objects</var>.h"</code></dt> |
| <dd><a name="index-_0023pragma-interface"></a> |
| <p>Use this directive in <em>header files</em> that define object classes, to save |
| space in most of the object files that use those classes. Normally, |
| local copies of certain information (backup copies of inline member |
| functions, debugging information, and the internal tables that implement |
| virtual functions) must be kept in each object file that includes class |
| definitions. You can use this pragma to avoid such duplication. When a |
| header file containing ‘<samp>#pragma interface</samp>’ is included in a |
| compilation, this auxiliary information is not generated (unless |
| the main input source file itself uses ‘<samp>#pragma implementation</samp>’). |
| Instead, the object files contain references to be resolved at link |
| time. |
| </p> |
| <p>The second form of this directive is useful for the case where you have |
| multiple headers with the same name in different directories. If you |
| use this form, you must specify the same string to ‘<samp>#pragma |
| implementation</samp>’. |
| </p> |
| </dd> |
| <dt><code>#pragma implementation</code></dt> |
| <dt><code>#pragma implementation "<var>objects</var>.h"</code></dt> |
| <dd><a name="index-_0023pragma-implementation"></a> |
| <p>Use this pragma in a <em>main input file</em>, when you want full output from |
| included header files to be generated (and made globally visible). The |
| included header file, in turn, should use ‘<samp>#pragma interface</samp>’. |
| Backup copies of inline member functions, debugging information, and the |
| internal tables used to implement virtual functions are all generated in |
| implementation files. |
| </p> |
| <a name="index-implied-_0023pragma-implementation"></a> |
| <a name="index-_0023pragma-implementation_002c-implied"></a> |
| <a name="index-naming-convention_002c-implementation-headers"></a> |
| <p>If you use ‘<samp>#pragma implementation</samp>’ with no argument, it applies to |
| an include file with the same basename<a name="DOCF4" href="#FOOT4"><sup>4</sup></a> as your source |
| file. For example, in <samp>allclass.cc</samp>, giving just |
| ‘<samp>#pragma implementation</samp>’ |
| by itself is equivalent to ‘<samp>#pragma implementation "allclass.h"</samp>’. |
| </p> |
| <p>In versions of GNU C++ prior to 2.6.0 <samp>allclass.h</samp> was treated as |
| an implementation file whenever you would include it from |
| <samp>allclass.cc</samp> even if you never specified ‘<samp>#pragma |
| implementation</samp>’. This was deemed to be more trouble than it was worth, |
| however, and disabled. |
| </p> |
| <p>Use the string argument if you want a single implementation file to |
| include code from multiple header files. (You must also use |
| ‘<samp>#include</samp>’ to include the header file; ‘<samp>#pragma |
| implementation</samp>’ only specifies how to use the file—it doesn’t actually |
| include it.) |
| </p> |
| <p>There is no way to split up the contents of a single header file into |
| multiple implementation files. |
| </p></dd> |
| </dl> |
| |
| <a name="index-inlining-and-C_002b_002b-pragmas"></a> |
| <a name="index-C_002b_002b-pragmas_002c-effect-on-inlining"></a> |
| <a name="index-pragmas-in-C_002b_002b_002c-effect-on-inlining"></a> |
| <p>‘<samp>#pragma implementation</samp>’ and ‘<samp>#pragma interface</samp>’ also have an |
| effect on function inlining. |
| </p> |
| <p>If you define a class in a header file marked with ‘<samp>#pragma |
| interface</samp>’, the effect on an inline function defined in that class is |
| similar to an explicit <code>extern</code> declaration—the compiler emits |
| no code at all to define an independent version of the function. Its |
| definition is used only for inlining with its callers. |
| </p> |
| <a name="index-fno_002dimplement_002dinlines-1"></a> |
| <p>Conversely, when you include the same header file in a main source file |
| that declares it as ‘<samp>#pragma implementation</samp>’, the compiler emits |
| code for the function itself; this defines a version of the function |
| that can be found via pointers (or by callers compiled without |
| inlining). If all calls to the function can be inlined, you can avoid |
| emitting the function by compiling with <samp>-fno-implement-inlines</samp>. |
| If any calls are not inlined, you will get linker errors. |
| </p> |
| <div class="footnote"> |
| <hr> |
| <h4 class="footnotes-heading">Footnotes</h4> |
| |
| <h3><a name="FOOT4" href="#DOCF4">(4)</a></h3> |
| <p>A file’s <em>basename</em> |
| is the name stripped of all leading path information and of trailing |
| suffixes, such as ‘<samp>.h</samp>’ or ‘<samp>.C</samp>’ or ‘<samp>.cc</samp>’.</p> |
| </div> |
| <hr> |
| <div class="header"> |
| <p> |
| 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> [<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> |
| </div> |
| |
| |
| |
| </body> |
| </html> |